Ranjeet2063 opened a new pull request, #26860:
URL: https://github.com/apache/datafusion/pull/26860

   # Which issue does this PR close?
   
   Closes #26624.
   
   # Rationale for this change
   
   When `datafusion.optimizer.prefer_hash_join = false`, queries where a 
`WHERE` clause makes an expression constant and that expression is then needed 
as a sort or join key above a `SortMergeJoinExec` failed during planning with 
`SanityCheckPlan`.
   
   There were two root causes in 
`datafusion/physical-expr/src/equivalence/class.rs`:
   1. `EquivalenceGroup::project` reconstructed each class using 
`EquivalenceClass::new(...)`, which initialized `constant` to `None` and 
dropped `cls.constant`. Consequently, single-element classes arising from 
projected expressions were considered trivial and filtered out, losing their 
constant status downstream.
   2. In `EquivalenceGroup::project_expr_indirect`, `Literal` leaves were 
treated as valid non-projected expressions, but `ScalarSubqueryExpr` leaves 
were not, causing expressions containing scalar subqueries to fail indirect 
projection.
   
   # What changes are included in this PR?
   
   - In `EquivalenceGroup::project`: preserved `cls.constant` when projecting 
equivalence classes through projection mappings.
   - In `EquivalenceGroup::project_expr_indirect`: recognized 
`ScalarSubqueryExpr` alongside `Literal` as an independent leaf expression.
   - Added unit regression test 
`test_project_preserves_constant_equivalence_class` in `class.rs` covering 
constant preservation across projection for expressions with literals and 
scalar subqueries.
   
   # Are these changes tested?
   
   Yes, new unit regression test 
`test_project_preserves_constant_equivalence_class` passes, as well as all 62 
equivalence tests and doc-tests in `datafusion-physical-expr`.
   
   # Are there any user-facing changes?
   
   No breaking API changes. Fixes `SanityCheckPlan` error under 
`datafusion.optimizer.prefer_hash_join = false`.
   


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

Reply via email to