rubenada commented on a change in pull request #1322: [CALCITE-3198]
ReduceExpressionsRule.FILTER_INSTANCE does not reduce 'NOT(x=a AND x=b)'
URL: https://github.com/apache/calcite/pull/1322#discussion_r305710205
##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -1624,6 +1626,24 @@ private RexNode simplifyOrs(List<RexNode> terms,
RexUnknownAs unknownAs) {
continue;
}
}
+ break;
+ case NOT_EQUALS:
+ Comparison notEqualsComparison =
+ Comparison.of(term, node -> RexUtil.isReferenceOrAccess(node,
false));
+ if (notEqualsComparison != null) {
+ Comparison prevNotEqualsComparison =
notEqualsComparisonMap.get(notEqualsComparison.ref);
+ if (prevNotEqualsComparison == null) {
+ notEqualsComparisonMap.put(notEqualsComparison.ref,
notEqualsComparison);
+ } else {
+ Comparable comparable1 = notEqualsComparison.literal.getValue();
+ Comparable comparable2 =
prevNotEqualsComparison.literal.getValue();
+ //noinspection unchecked
+ if (comparable1.compareTo(comparable2) != 0) {
+ return rexBuilder.makeLiteral(true);
Review comment:
Thanks for your feedback, @kgyrtkirk .
If I understand correctly, you say that the simplification
`x != 0 || x!= 1 => TRUE`
Can only be done in unknownas.TRUE mode or if x's type is not nullable.
Otherwise, it should be simplified as:
`x != 0 || x!= 1 => x IS NOT NULL`
Regarding the expression:
`x = 0 && x = 1 => FALSE`
I have verified, and right now it seems that this is only simplified with
unknownas.FALSE. I assume this behavior is correct, right?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services