thomasrebele commented on code in PR #4646:
URL: https://github.com/apache/calcite/pull/4646#discussion_r2559204828
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -1153,16 +1153,15 @@ private RexNode simplifyIs(RexCall call, RexUnknownAs
unknownAs) {
return rexBuilder.makeLiteral(true);
}
if (RexUtil.isLosslessCast(a)) {
- if (!a.getType().isNullable()) {
- return rexBuilder.makeLiteral(true);
- }
- return rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
RexUtil.removeCast(a));
+ a = RexUtil.removeCast(a);
+ // to keep this simplification, we must return IS NOT NULL(a),
+ // even if we cannot do anything else
}
if (predicates.pulledUpPredicates.contains(a)) {
return rexBuilder.makeLiteral(true);
}
if (hasCustomNullabilityRules(a.getKind())) {
- return null;
+ return rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, a);
Review Comment:
I've added [a
comment](https://github.com/apache/calcite/pull/4646/files/1fc0329b966dcd82aaeb52bd04a09ae8781000be#diff-047d75692a99d7b5c0d9b1aefc04549ec766e0a45a895b2e04a2cfa0fa6b073eR1157-R1158)
why we need to return `IS NOT NULL(a)`. If we return just `null`, we would not
remove the superfluous lossless cast.
I'll add a check whether a has changed.
Thank you for pointing out that there exist a version of makeCall that
allows to specify the source position. The [existing
fallback](https://github.com/thomasrebele/calcite/blob/1fc0329b966dcd82aaeb52bd04a09ae8781000be/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1138-L1140)
has no source position either. Reading
[CALCITE-6071](https://issues.apache.org/jira/browse/CALCITE-6071), it seems
that only calls that may throw should be annotated with the source position. As
`IS NULL` / `IS NOT NULL` don't throw themselves, they would not need the
source position.
--
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]