qzyu999 commented on issue #23692: URL: https://github.com/apache/datafusion/issues/23692#issuecomment-5012777326
## Root Cause Found: SQL Parser Operator Precedence The root cause is **sqlparser-rs operator precedence**, not DataFusion's type_coercion rule. ### Proof Adding explicit parentheses makes the query work: \\\sql -- FAILS: parsed as t1.a IS NOT DISTINCT FROM (t2.a AND t1.b) IS NOT DISTINCT FROM t2.b SELECT * FROM t1 LEFT ANTI JOIN t2 ON t1.a IS NOT DISTINCT FROM t2.a AND t1.b IS NOT DISTINCT FROM t2.b -- WORKS: explicit grouping SELECT * FROM t1 LEFT ANTI JOIN t2 ON (t1.a IS NOT DISTINCT FROM t2.a) AND (t1.b IS NOT DISTINCT FROM t2.b) \\\ ### Verification I wrote a unit test that constructs the Join node directly (bypassing the SQL parser) with properly qualified columns and multi-condition IS NOT DISTINCT FROM. **It passes the TypeCoercion analyzer without error.** This proves the type_coercion rule is correct it's the parser that produces a malformed expression tree. ### Fix The fix belongs in **sqlparser-rs**: \IS NOT DISTINCT FROM\ should have higher precedence than \AND\ (consistent with PostgreSQL where \IS\ operators bind tighter than boolean connectives). **Workaround for users:** Wrap each \IS NOT DISTINCT FROM\ condition in explicit parentheses. This is what we're doing in PyIceberg's DataFusion backend. This issue is effectively a duplicate of / related to #22461 (operator precedence inconsistency with modern PostgreSQL). -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
