rubenada commented on code in PR #4465:
URL: https://github.com/apache/calcite/pull/4465#discussion_r2414562208
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -767,6 +772,49 @@ private <C extends Comparable<C>> RexNode
simplifyComparison(RexCall e,
return simplifyUsingPredicates(e2, clazz);
}
+
+ /**
+ * If this RexNode is a comparison against NULL, return FALSE, otherwise
return it unchanged.
+ * This is a static simplified version of the function below.
+ */
+ public static RexNode simplifyComparisonWithNull(RexNode e, RexBuilder
rexBuilder) {
Review Comment:
I haven't checked in detail, but could we keep the logic in just one single
method/location? e.g. something like:
```
public static RexNode simplifyComparisonWithNull(RexNode e, RexBuilder
rexBuilder) {
return simplifyComparisonWithNull(e, rexBuilder, RexUnknownAs.FALSE);
}
public RexNode simplifyComparisonWithNull(RexNode e, RexUnknownAs unknownAs)
{
return simplifyComparisonWithNull(e, rexBuilder, unknownAs);
}
/** ... javadoc */
private static RexNode simplifyComparisonWithNull(RexNode e, RexBuilder
rexBuilder, RexUnknownAs unknownAs) {
final Comparison comparison = Comparison.of(e);
if (comparison != null) {
boolean againstNull = comparison.literal.isNull();
// There is another possibility to check: in a comparison like 1 =
null,
// the "non-literal" side of the Comparison can be null
if (comparison.ref instanceof RexLiteral) {
againstNull = againstNull || ((RexLiteral) comparison.ref).isNull();
}
if (againstNull) {
return unknownAs == FALSE
? rexBuilder.makeLiteral(false)
: rexBuilder.makeNullLiteral(e.getType());
}
}
return e;
}
```
--
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]