macroguo-ghy commented on code in PR #3416:
URL: https://github.com/apache/calcite/pull/3416#discussion_r1327973848
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2060,6 +2060,25 @@ private RexNode simplifyOrs(List<RexNode> terms,
RexUnknownAs unknownAs) {
}
}
break;
+ case IS_NOT_TRUE:
+ if (terms.contains(((RexCall) term).getOperands().get(0))) {
+ return trueLiteral;
+ }
+ break;
+ case NOT:
+ RexNode x = ((RexCall) term).getOperands().get(0);
+ if (terms.contains(x)) {
Review Comment:
Thanks for your explaination, I got your points.
For the first case `x or not(x)`, I add a new limitation where `x` must be
safeExpression.
But for the second case `a or x or not(x) or b`, I think we can simplify `x
or not(x)` no matter whether `a` and `b` safe or not.
Thinking about a simple case: `true or unSafeUdf()`, calcite will simplify
this expression to `true`. And I have tested `select * from t where 1/0 or
true` expression in mysql and sparksql, both of them will simpilfy this
expression to `true`. And third, in most of programing language (like Java,
C++, Python), they always simplify `true or someConditions` to `true` in if
clause (A little different, it is Short-circuit OR actully, but we check all
items).
So I think we don't need to care about outside items whether safe or not.
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2060,6 +2060,25 @@ private RexNode simplifyOrs(List<RexNode> terms,
RexUnknownAs unknownAs) {
}
}
break;
+ case IS_NOT_TRUE:
+ if (terms.contains(((RexCall) term).getOperands().get(0))) {
+ return trueLiteral;
Review Comment:
Thanks for your explaination, I got your points.
For the first case `x or not(x)`, I add a new limitation where `x` must be
safeExpression.
But for the second case `a or x or not(x) or b`, I think we can simplify x
or not(x) no matter whether `a` and `b` safe or not.
Thinking about a simple case: `true or unSafeUdf()`, calcite will simplify
this expression to `true`. And I have tested `select * from t where 1/0 or
true` expression in mysql and sparksql, both of them will simpilfy this
expression to `true`. And third, in most of programing language(like Java, C++,
Python), they always simplify `true or someConditions` to `true` in if clause
(A little different, it is Short-circuit OR actully, but we check all items).
So I think we don't need to care about outside items whether safe or not.
--
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]