xuzifu666 commented on code in PR #5295:
URL: https://github.com/apache/calcite/pull/5295#discussion_r4133941858


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2013,11 +2013,13 @@ private <C extends Comparable<C>> RexNode 
simplifyAnd2ForUnknownAsFalse(
       // Simplify BOOLEAN expressions if possible
       while (term.getKind() == SqlKind.EQUALS) {
         RexCall call = (RexCall) term;
-        if (call.getOperands().get(0).isAlwaysTrue()) {
+        if (call.getOperands().get(0).isAlwaysTrue()
+            && call.getOperands().get(1).getType().getSqlTypeName() == 
SqlTypeName.BOOLEAN) {

Review Comment:
   Good idea, done @julianhyde . The loop now starts with a well-formedness 
guard: unless both operands of =` have the same type name (e.g.=(x, TRUE) with 
VARCHAR or INTEGER x is malformed), it breaks without simplifying. This is 
equivalent to the previous check, sinceisAlwaysTrue() can only be true for a 
BOOLEAN expression, but it states the precondition up front. I compare 
`getSqlTypeName()` rather than `RelDataType.equals`, because `TRUE` is `NOT 
NULL` and equals would compare nullability, blocking the valid simplification 
of=(nullable Bool X, TRUE).



-- 
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]

Reply via email to