Permalink
Browse files

TEIID-2452 correcting like_regex pushdown

  • Loading branch information...
1 parent 9712b7e commit 928d2ee2284f995d4e389afa09bb74ed5003ef2f @shawkins shawkins committed Mar 29, 2013
@@ -37,6 +37,7 @@
import org.teiid.language.*;
import org.teiid.language.Comparison.Operator;
+import org.teiid.language.Like.MatchMode;
import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.SetQuery.Operation;
import org.teiid.language.visitor.CollectorVisitor;
@@ -576,6 +577,34 @@ public void visit(ColumnReference obj) {
super.visit(obj);
}
+ @Override
+ public void visit(Call call) {
+ if (oracleSuppliedDriver && call.getReturnType() == null && call.getResultSetColumnTypes().length > 0 && call.getMetadataObject() != null && call.getMetadataObject().getProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, false) == null) {
+ //oracle returns the resultset as a parameter
+ call.setReturnType(RefCursorType.class);
+ }
+ super.visit(call);
+ }
+
+ @Override
+ public void visit(Like obj) {
+ if (obj.getMode() == MatchMode.REGEX) {
+ if (obj.isNegated()) {
+ buffer.append("NOT("); //$NON-NLS-1$
+ }
+ buffer.append("REGEXP_LIKE("); //$NON-NLS-1$
+ append(obj.getLeftExpression());
+ buffer.append(", "); //$NON-NLS-1$
+ append(obj.getRightExpression());
+ buffer.append(")"); //$NON-NLS-1$
+ if (obj.isNegated()) {
+ buffer.append(")"); //$NON-NLS-1$
+ }
+ } else {
+ super.visit(obj);
+ }
+ }
+
};
}
@@ -706,11 +735,6 @@ public boolean supportsLikeRegex() {
return true;
}
- @Override
- public String getLikeRegexString() {
- return "REGEXP_LIKE"; //$NON-NLS-1$
- }
-
public void setOracleSuppliedDriver(boolean oracleNative) {
this.oracleSuppliedDriver = oracleNative;
}
@@ -721,18 +745,6 @@ public boolean isOracleSuppliedDriver() {
}
@Override
- public List<?> translate(LanguageObject obj, ExecutionContext context) {
- if (oracleSuppliedDriver && obj instanceof Call) {
- Call call = (Call)obj;
- if (call.getReturnType() == null && call.getResultSetColumnTypes().length > 0 && call.getMetadataObject() != null && call.getMetadataObject().getProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, false) == null) {
- //oracle returns the resultset as a parameter
- call.setReturnType(RefCursorType.class);
- }
- }
- return super.translate(obj, context);
- }
-
- @Override
protected void registerSpecificTypeOfOutParameter(
CallableStatement statement, Class<?> runtimeType, int index)
throws SQLException {
@@ -878,7 +878,7 @@ public void helpTestVisitor(String vdb, String input, String expectedOutput) thr
@Test public void testLikeRegex() throws Exception {
String input = "SELECT intkey FROM BQT1.SMALLA where stringkey like_regex 'ab.*c+' and stringkey not like_regex 'ab{3,5}c'"; //$NON-NLS-1$
- String output = "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.StringKey REGEXP_LIKE 'ab.*c+' AND SmallA.StringKey NOT REGEXP_LIKE 'ab{3,5}c'"; //$NON-NLS-1$
+ String output = "SELECT SmallA.IntKey FROM SmallA WHERE REGEXP_LIKE(SmallA.StringKey, 'ab.*c+') AND NOT(REGEXP_LIKE(SmallA.StringKey, 'ab{3,5}c'))"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input, output,

0 comments on commit 928d2ee

Please sign in to comment.