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 2022/02/14 11:40:10 UTC

[GitHub] [calcite] asolimando commented on a change in pull request #2699: [CALCITE-4988] ((A IS NOT NULL OR B) AND A IS NOT NULL) can't be simp…

asolimando commented on a change in pull request #2699:
URL: https://github.com/apache/calcite/pull/2699#discussion_r805757859



##########
File path: core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
##########
@@ -2157,6 +2157,82 @@ private void checkExponentialCnf(int n) {
     checkSimplify(isNotNull(cast(i2, intType)), "true");
   }
 
+  /**
+   * Unit test for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4988">[CALCITE-4988]
+   * ((A IS NOT NULL OR B) AND A IS NOT NULL) can't be simplify to (A IS NOT NULL)
+   * When A is deterministic</a>. */
+  @Test void testSimplifyIsNotNullWithDeterministic() {
+    // "(A IS NOT NULL OR B) AND A IS NOT NULL" when A is deterministic
+    // ==>
+    // "A IS NOT NULL"
+    SqlOperator dc = getDeterministicOperator();
+    checkSimplify2(
+        and(or(isNotNull(rexBuilder.makeCall(dc)), gt(vInt(2), literal(2))),
+            isNotNull(rexBuilder.makeCall(dc))),
+        "AND(OR(IS NOT NULL(DC()), >(?0.int2, 2)), IS NOT NULL(DC()))",
+        "IS NOT NULL(DC())");
+  }
+
+  @Test void testSimplifyIsNotNullWithDeterministic2() {
+    // "(A IS NOT NULL AND B) OR A IS NULL" when A is deterministic
+    // ==>
+    // "A IS NULL OR B"
+    SqlOperator dc = getDeterministicOperator();
+    checkSimplify(
+            or(and(isNotNull(rexBuilder.makeCall(dc)), gt(vInt(2), literal(2))),
+                    isNull(rexBuilder.makeCall(dc))),
+            "OR(IS NULL(DC()), >(?0.int2, 2))");
+  }
+
+  @Test void testSimplifyIsNotNullWithNoDeterministic() {
+    // "(A IS NOT NULL OR B) AND A IS NOT NULL" when A is not deterministic
+    // ==>
+    // "(A IS NOT NULL OR B) AND A IS NOT NULL"
+    SqlOperator ndc = getNoDeterministicOperator();
+    checkSimplifyUnchanged(
+        and(or(isNotNull(rexBuilder.makeCall(ndc)), gt(vInt(2), literal(2))),
+            isNotNull(rexBuilder.makeCall(ndc))));
+  }
+
+  @Test void testSimplifyIsNotNullWithNoDeterministic2() {

Review comment:
       I can't spot any difference w.r.t. `testSimplifyIsNotNullWithNoDeterministic`, is this a copy-paste error or am I missing something?




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

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