xuzifu666 commented on PR #5295:
URL: https://github.com/apache/calcite/pull/5295#issuecomment-6014163464

   > The same defect remains when the operands are swapped. 
`simplifyComparison` checks only that `o0` is BOOLEAN 
([RexSimplify.java#L751](https://github.com/apache/calcite/blob/f83d5ef65a442b62b26c74cfe7d6c0c1c85922d6/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L751)),
 and `Comparison.of` then swaps the operands so that `cmp.ref` is the VARCHAR 
one. With this PR applied, in every `RexUnknownAs` mode:
   > 
   > Input      Result
   > `=(true, ?0.varchar0)`     `?0.varchar0`
   > `AND(=(true, ?0.varchar0), =(true, ?0.varchar1))`  `AND(?0.varchar0, 
?0.varchar1)`, of type VARCHAR
   > `AND(=(false, ?0.varchar0), =(false, ?0.varchar1))`        
`AND(NOT(?0.varchar0), NOT(?0.varchar1))`
   > `AND(<>(false, ?0.varchar0), <>(false, ?0.varchar1))`      
`AND(?0.varchar0, ?0.varchar1)`
   > A front end that builds `=(TRUE, c)` without a cast, as Flink does in the 
JIRA, still gets the plan 
[CALCITE-5907](https://issues.apache.org/jira/browse/CALCITE-5907) reports for 
`WHERE TRUE = c AND TRUE = d`. `testSimplifyAndEqualityTrue` needs these four 
inputs too.
   > 
   > The JIRA summary, and with it the PR title and the squashed commit, does 
not name the symptom, and the bug is wider than `AND`. Something like 
`RexSimplify replaces a comparison with a BOOLEAN literal by a non-BOOLEAN 
operand` covers the swapped and FALSE forms as well.
   
   Good catch, thank you @vlsi ! The swapped case indeed slipped through: 
simplifyComparison only checked o0 and Comparison.of happily swapped the 
operands, so =(TRUE, c) still collapsed to c. Fixed per your suggestion — there 
is now a private isWellFormed(left, right) helper (same type name on both 
sides), called both from the AND loop and from simplifyComparison before the 
BOOLEAN branch, so it now guards both directions and the = false / <> false 
forms. testSimplifyAndEqualityTrue covers the four inputs from your table (as 
checkSimplifyUnchanged), plus AND(=($0, true), ?0.bool1) with $0 of type ANY; 
the non-BOOLEAN inputs run with withParanoid(false) so a regression reports the 
simplified expression rather than a ClassCastException.


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