xiayutianwei1994 commented on a change in pull request #2673:
URL: https://github.com/apache/calcite/pull/2673#discussion_r779548486



##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -1506,8 +1506,46 @@ RexNode simplifyAnd(RexCall e, RexUnknownAs unknownAs) {
     return simplifyAnd2(terms, notTerms);
   }
 
+  boolean satisfy(Set<RexNode> condition, RexNode term) {
+    List<RexNode> terms = new ArrayList<>();
+    RelOptUtil.decomposeConjunction(term, terms);
+    return condition.containsAll(terms);
+  }
+
+  boolean satisfyForUnknownAsFalse(Set<RexNode> condition, Set<RexNode> 
notNullOperands,
+      RexNode node) {
+    List<RexNode> terms = new ArrayList<>();
+    RelOptUtil.decomposeConjunction(node, terms);
+    for (RexNode term : terms) {
+      if (!condition.contains(term) && !(term.getKind() == SqlKind.IS_NOT_NULL 
&& notNullOperands
+          .contains(((RexCall) term).getOperands().get(0)))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  boolean containSatisfyTerm(RexNode node, 
java.util.function.Predicate<RexNode> satisfy) {
+    List<RexNode> terms = new ArrayList<>();
+    RelOptUtil.decomposeDisjunction(node, terms);
+    for (RexNode term : terms) {
+      if (satisfy.test(term)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   // package-protected only to support a deprecated method; treat as private
   RexNode simplifyAnd2(List<RexNode> terms, List<RexNode> notTerms) {
+    Set<RexNode> termsSet = new HashSet<>(terms);

Review comment:
       Thanks for your comment.
   If use unknown as unknown, some predicate will not be simplified to IS NOT 
NULL or IS NULL like the third test case I added.
   And sometimes, predicate like (C0+C1) IS NOT NULL will not be pulled up. 
Because we only pull up predicate like C0 IS NOT NULL.
   There also has another question: If (A OR B) AND A, predicate A is 
nondeterministic, whether it can be simplified to A.
   Now we only pull up predicate which is deterministic.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to