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/08/18 10:07:35 UTC

[GitHub] [calcite] liyafan82 commented on a change in pull request #2105: [CALCITE-4159] Simplify always-true expressions (such as LIKE '%') to TRUE

liyafan82 commented on a change in pull request #2105:
URL: https://github.com/apache/calcite/pull/2105#discussion_r472066153



##########
File path: core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
##########
@@ -180,4 +203,27 @@ public RelOptPredicateList shift(RexBuilder rexBuilder, int offset) {
         RexUtil.shift(leftInferredPredicates, offset),
         RexUtil.shift(rightInferredPredicates, offset));
   }
+
+  /** Returns whether an expression is effectively NOT NULL due to an
+   * {@code e IS NOT NULL} condition in this predicate list. */
+  public boolean isEffectivelyNotNull(RexNode e) {
+    if (!e.getType().isNullable()) {
+      return true;
+    }
+    for (RexNode p : pulledUpPredicates) {
+      if (p.getKind() == SqlKind.IS_NOT_NULL
+          && ((RexCall) p).getOperands().get(0).equals(e)) {
+        return true;
+      }
+    }
+    if (SqlKind.COMPARISON.contains(e.getKind())) {
+      // A comparison with a literal, such as 'ref < 10', is not null if 'ref'
+      // is not null.
+      RexCall call = (RexCall) e;
+      if (call.getOperands().get(1) instanceof RexLiteral) {
+        return isEffectivelyNotNull(call.getOperands().get(0));

Review comment:
       do we also need to consider cases such as '10 > ref' here?




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