You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/11/04 12:38:44 UTC

[GitHub] [calcite] godfreyhe commented on a change in pull request #2238: [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified to `a = 1`

godfreyhe commented on a change in pull request #2238:
URL: https://github.com/apache/calcite/pull/2238#discussion_r517313582



##########
File path: core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
##########
@@ -1774,6 +1770,27 @@ private void checkExponentialCnf(int n) {
     checkSimplify2(e, "SEARCH(?0.int0, Sarg[10])", "=(?0.int0, 10)");
   }
 
+  @Test void testSimplifyInAnd() {
+    // deptno in (20, 10) and deptno = 10
+    //   ==>
+    // deptno = 10
+    checkSimplify2(
+        and(
+            in(vInt(), literal(20), literal(10)),
+            eq(vInt(), literal(10))),
+        "SEARCH(?0.int0, Sarg[10])",
+        "=(?0.int0, 10)");
+
+    // deptno in (20, 10) and deptno = 30
+    //   ==>
+    // false
+    checkSimplify(
+        and(
+        in(vInt(), literal(20), literal(10)),
+        eq(vInt(), literal(30))),
+        "false");
+  }
+

Review comment:
       I find `deptno > 0 and deptno in (20, 10)` can' t be simplified as `deptno > 0`

##########
File path: core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
##########
@@ -1774,6 +1770,27 @@ private void checkExponentialCnf(int n) {
     checkSimplify2(e, "SEARCH(?0.int0, Sarg[10])", "=(?0.int0, 10)");
   }
 
+  @Test void testSimplifyInAnd() {
+    // deptno in (20, 10) and deptno = 10
+    //   ==>
+    // deptno = 10
+    checkSimplify2(
+        and(
+            in(vInt(), literal(20), literal(10)),
+            eq(vInt(), literal(10))),
+        "SEARCH(?0.int0, Sarg[10])",
+        "=(?0.int0, 10)");
+
+    // deptno in (20, 10) and deptno = 30
+    //   ==>
+    // false
+    checkSimplify(
+        and(
+        in(vInt(), literal(20), literal(10)),
+        eq(vInt(), literal(30))),
+        "false");
+  }
+

Review comment:
       I find `deptno > 0 or deptno in (20, 10)` can' t be simplified as `deptno > 0`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org