Author: jolee
Date: 2013-02-05 15:21:35 -0500 (Tue, 05 Feb 2013)
New Revision: 4551
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-2366: If where clause contains both equal and greater then conditions then query
may return no results
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2013-02-05
20:09:09 UTC (rev 4550)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2013-02-05
20:21:35 UTC (rev 4551)
@@ -1231,8 +1231,14 @@
if (cc.getOperator() == CompareCriteria.EQ) {
exprMap.put(cc.getLeftExpression(), cc);
} else if (modified) {
- newCrits.add(sc);
- exprMap.put(sc.getExpression(), sc);
+ if (sc.getNumberOfValues() == 1) {
+ CompareCriteria comp = new CompareCriteria(sc.getExpression(),
CompareCriteria.EQ, (Expression)sc.getValues().iterator().next());
+ newCrits.add(comp);
+ exprMap.put(sc.getExpression(), comp);
+ } else {
+ newCrits.add(sc);
+ exprMap.put(sc.getExpression(), sc);
+ }
return null;
}
} else {
@@ -1240,7 +1246,7 @@
if (cc1.getOperator() == CompareCriteria.NE) {
exprMap.put(cc.getLeftExpression(), cc);
} else if (cc1.getOperator() == CompareCriteria.EQ) {
- if (!Evaluator.compare(cc1,
((Constant)cc1.getRightExpression()).getValue(),
((Constant)cc.getRightExpression()).getValue())) {
+ if (!Evaluator.compare(cc,
((Constant)cc1.getRightExpression()).getValue(),
((Constant)cc.getRightExpression()).getValue())) {
return FALSE_CRITERIA;
}
return null;
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2013-02-05
20:09:09 UTC (rev 4550)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2013-02-05
20:21:35 UTC (rev 4551)
@@ -2410,6 +2410,18 @@
helpTestRewriteCriteria("pm1.g1.e2 > 5 and pm1.g1.e2 < 2", "1 =
0");
}
+ @Test public void testRewritePredicateOptimization8() throws Exception {
+ helpTestRewriteCriteria("pm1.g1.e2 = 2 and pm1.g1.e2 > 1",
"pm1.g1.e2 = 2");
+ }
+
+ @Test public void testRewritePredicateOptimization8a() throws Exception {
+ helpTestRewriteCriteria("pm1.g1.e2 in (0, 2) and pm1.g1.e2 > 1",
"pm1.g1.e2 = 2");
+ }
+
+ @Test public void testRewritePredicateOptimization9() throws Exception {
+ helpTestRewriteCriteria("not(pm1.g1.e2 = 2 and pm1.g1.e2 = 3)",
"(pm1.g1.e2 <> 2) OR (pm1.g1.e2 <> 3)");
+ }
+
@Test public void testRewritePredicateOptimizationOr() throws Exception {
helpTestRewriteCriteria("pm1.g1.e2 in (5, 6) or pm1.g1.e2 = 2",
"pm1.g1.e2 IN (2, 5, 6)");
}
Show replies by date