Skip to content

Commit

Permalink
TEIID-2452 correcting like_regex pushdown
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Mar 29, 2013
1 parent 9712b7e commit 928d2ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

};
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -720,18 +744,6 @@ public boolean isOracleSuppliedDriver() {
return oracleSuppliedDriver;
}

@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)
Expand Down
Expand Up @@ -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,
Expand Down

0 comments on commit 928d2ee

Please sign in to comment.