You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "rubenada (via GitHub)" <gi...@apache.org> on 2026/08/18 09:10:02 UTC
Re: [PR] [CALCITE-7722] RexSimplify IS [NOT] NULL on a safe operator with Strong policy ANY and unsafe operands can be further simplified [calcite]
rubenada commented on code in PR #5184:
URL: https://github.com/apache/calcite/pull/5184#discussion_r3802661608
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -1197,15 +1197,40 @@ private RexNode simplifyIs(RexCall call, RexUnknownAs unknownAs) {
if (hasCustomNullabilityRules(a.getKind())) {
return simplifiedResult;
}
- if (!isSafe) {
- return simplifiedResult;
- }
switch (Strong.policy(a)) {
case NOT_NULL:
+ // Drops the subtree; require full-tree safety so we don't hide runtime
+ // errors inside
+ if (!isSafe) {
+ return simplifiedResult;
+ }
return rexBuilder.makeLiteral(true);
case ANY:
// "f" is a strong operator, so "f(operand0, operand1) IS NOT NULL"
- // simplifies to "operand0 IS NOT NULL AND operand1 IS NOT NULL"
+ // simplifies to "operand0 IS NOT NULL AND operand1 IS NOT NULL".
Review Comment:
comment simplified
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -1197,15 +1197,40 @@ private RexNode simplifyIs(RexCall call, RexUnknownAs unknownAs) {
if (hasCustomNullabilityRules(a.getKind())) {
return simplifiedResult;
}
- if (!isSafe) {
- return simplifiedResult;
- }
switch (Strong.policy(a)) {
case NOT_NULL:
+ // Drops the subtree; require full-tree safety so we don't hide runtime
+ // errors inside
+ if (!isSafe) {
+ return simplifiedResult;
+ }
return rexBuilder.makeLiteral(true);
case ANY:
// "f" is a strong operator, so "f(operand0, operand1) IS NOT NULL"
- // simplifies to "operand0 IS NOT NULL AND operand1 IS NOT NULL"
+ // simplifies to "operand0 IS NOT NULL AND operand1 IS NOT NULL".
+ // This branch PRESERVES the operand subtrees (each is either recursively
+ // simplified, or rewrapped verbatim as IS NOT NULL(operand)), so it only
+ // needs SHALLOW safety of the outer operator. Requiring full-tree safety
+ // here suppresses common peels like (CAST(str):DOUBLE + 1.0) IS NOT NULL
+ // → CAST(str):DOUBLE IS NOT NULL just because a non-lossless CAST lives
+ // deeper in the tree, even though that CAST would still be evaluated
+ // inside the rewrapped IS NOT NULL(operand).
+ if (!SafeRexVisitor.INSTANCE.isShallowSafe(a)) {
+ return simplifiedResult;
+ }
+ // The peel only preserves runtime semantics when each operand can be
Review Comment:
comment simplified
--
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