You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "kgyrtkirk (via GitHub)" <gi...@apache.org> on 2023/06/26 07:10:15 UTC

[GitHub] [calcite] kgyrtkirk commented on a diff in pull request #3279: [CALCITE-5798] '(1 < x) IS NOT TRUE' when x is not nullable should be simplified to '1 >= x'

kgyrtkirk commented on code in PR #3279:
URL: https://github.com/apache/calcite/pull/3279#discussion_r1241723952


##########
core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java:
##########
@@ -236,14 +236,18 @@ public boolean isEffectivelyNotNull(RexNode e) {
       }
     }
     if (SqlKind.COMPARISON.contains(e.getKind())) {
-      // A comparison with a (non-null) literal, such as 'ref < 10', is not null if 'ref'
-      // is not null.
+      // A comparison with a (non-null) literal, such as 'ref < 10', or '10 < ref',
+      // is not null if 'ref' is not null.
       List<RexNode> operands = ((RexCall) e).getOperands();
       // We can have just one operand in case e.g. of a RexSubQuery with IN operator.
       if (operands.size() > 1 && operands.get(1) instanceof RexLiteral
           && !((RexLiteral) operands.get(1)).isNull()) {
         return isEffectivelyNotNull(operands.get(0));
       }
+      if (operands.size() > 1 && operands.get(0) instanceof RexLiteral
+          && !((RexLiteral) operands.get(0)).isNull()) {
+        return isEffectivelyNotNull(operands.get(1));
+      }

Review Comment:
   I wonder if it would make sense to instead of this:
   
   * push those `RexLiteral` related stuff as part of `isEffectivelyNotNull` somewhere at the beginning
   * replace this block with something like:
   ```
   for(int i=0;i<operands.size();i++) {
     if(!isEffectivelyNotNull(operands.get(0)) {
       return false;
     }
   }
   return true;
   ```
   so that it will handle `x > y is not true` ; in case `x` and `y` is known to be not null



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