Skip to content

Commit

Permalink
TEIID-4120 using the appropriate comparison for sdo functions
Browse files Browse the repository at this point in the history
Conflicts:
	engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
  • Loading branch information
shawkins committed Apr 6, 2016
1 parent 9aa35ca commit ac4c457
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.teiid.GeometryInputSource;
import org.teiid.core.types.BinaryType;
Expand Down Expand Up @@ -88,6 +90,15 @@ public class OracleExecutionFactory extends JDBCExecutionFactory {
public static final String WITHIN_DISTANCE = "sdo_within_distance"; //$NON-NLS-1$
public static final String NEAREST_NEIGHBOR_DISTANCE = "sdo_nn_distance"; //$NON-NLS-1$
public static final String ORACLE_SDO = "Oracle-SDO"; //$NON-NLS-1$

private static final Set<String> STRING_BOOLEAN_FUNCTIONS = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
static {
STRING_BOOLEAN_FUNCTIONS.addAll(
Arrays.asList(SourceSystemFunctions.ST_DISJOINT, SourceSystemFunctions.ST_CONTAINS,
SourceSystemFunctions.ST_CROSSES, SourceSystemFunctions.ST_INTERSECTS,
SourceSystemFunctions.ST_OVERLAPS, SourceSystemFunctions.ST_TOUCHES,
SourceSystemFunctions.ST_EQUALS));
}

private final class DateAwareExtract extends ExtractFunctionModifier {
@Override
Expand Down Expand Up @@ -603,6 +614,15 @@ public void visit(Comparison obj) {
p.setType(FixedCharType.class);
}
}
if (obj.getLeftExpression().getType() == TypeFacility.RUNTIME_TYPES.BOOLEAN
&& (obj.getLeftExpression() instanceof Function)
&& obj.getRightExpression() instanceof Literal) {
Function f = (Function)obj.getLeftExpression();
if (STRING_BOOLEAN_FUNCTIONS.contains(f.getName())) {
Boolean b = (Boolean)((Literal)obj.getRightExpression()).getValue();
obj.setRightExpression(new Literal(b!=null?(b?"TRUE":"FALSE"):null, TypeFacility.RUNTIME_TYPES.STRING)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
super.visit(obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,13 @@ public void testGeometryIntersects() throws Exception {
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}

@Test
public void testGeometryComparison() throws Exception {
String input = "select shape from cola_markets where ST_Contains(shape, shape) and NOT ST_Intersects(shape, shape)"; //$NON-NLS-1$
String output = "SELECT SDO_UTIL.TO_GMLGEOMETRY(COLA_MARKETS.SHAPE) FROM COLA_MARKETS WHERE SDO_RELATE(COLA_MARKETS.SHAPE, COLA_MARKETS.SHAPE, 'mask=contains') = 'TRUE' AND SDO_RELATE(COLA_MARKETS.SHAPE, COLA_MARKETS.SHAPE, 'mask=anyinteract') <> 'TRUE'"; //$NON-NLS-1$
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}

@Test
public void testGeometryInsert() throws Exception {
String input = "insert into cola_markets(name,shape) values('foo124', ST_GeomFromText('POINT (300 100)', 8307))"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,13 @@ private Criteria rewriteCriteria(NotCriteria criteria) throws TeiidComponentExce
return rewriteCriteria(((NotCriteria)innerCrit).getCriteria());
}
innerCrit = rewriteCriteria(innerCrit);
if (innerCrit instanceof Negatable) {
((Negatable) innerCrit).negate();
return rewriteCriteria(innerCrit);
}
if (innerCrit instanceof NotCriteria) {
return rewriteCriteria(((NotCriteria)innerCrit).getCriteria());
}
if(innerCrit == TRUE_CRITERIA) {
return FALSE_CRITERIA;
} else if(innerCrit == FALSE_CRITERIA) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,4 +1765,9 @@ private void addTestData() {
helpTestRewriteCommand(sql, "SELECT (SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS a LIMIT 2) FROM pm1.g2");
}

@Test public void testRewriteCritBooleanExpression() {
helpTestRewriteCriteria("not (pm1.g1.e3)", //$NON-NLS-1$
"pm1.g1.e3 <> TRUE" ); //$NON-NLS-1$
}

}

0 comments on commit ac4c457

Please sign in to comment.