herunkang2018 commented on code in PR #3267:
URL: https://github.com/apache/calcite/pull/3267#discussion_r1231641152
##########
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
Review Comment:
@NobiGo this is to improve the `isEffectivelyNotNull` logic for `10 < ref`
when pulled up predicates contain `ref is not null`, then `10 < ref`'s
`isEffectivelyNotNull` will be `true`. This is useful to simplify the nested
`RexNode`, like `is not true(10 < ref)`, and it will be simplified to `10 >=
ref` which is more concise and useful for further simplification in this Jira.
Besides, another reasonable way is to split this part of code to another
Jira, and it will be more clear why make these changes. @NobiGo What do you
think?
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -1887,11 +1887,10 @@ private static <C extends Comparable<C>> RangeSet<C>
residue(RexNode ref,
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
final RexCall call = (RexCall) predicate;
- if (call.operands.get(0).equals(ref)
- && call.operands.get(1) instanceof RexLiteral) {
- final RexLiteral literal = (RexLiteral) call.operands.get(1);
- final C c1 = literal.getValueAs(clazz);
- assert c1 != null : "value must not be null in " + literal;
+ final Comparison comparison = Comparison.of(call);
Review Comment:
We change here because previous logic only checks `ref > 1`, not `1 < ref`,
we use `Comparison` to refine this part of code, and support the reverse order
comparison.
--
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]