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

   ## Which issue does this PR close?
   
   - Closes #23374.
   
   ## Rationale for this change
   
   `UnionExec::try_new` can panic while computing equivalence properties if 
stale constant metadata is carried across a projection and then rewritten to 
the union output schema.
   
   In the observed shape, a filter such as `ticker = 'ESU6'` can leave a 
uniform string constant in equivalence properties. After a parent projection 
drops `ticker`, union property schema rewriting can see the remaining column 
slot as a timestamp column and attempt to cast `'ESU6'` to `Timestamp`, which 
fails during planning.
   
   Equivalence constants are optimizer metadata, so an unrepresentable constant 
after schema rewrite should be discarded rather than failing query planning.
   
   ## What changes are included in this PR?
   
   - Drops a uniform constant during `EquivalenceProperties::with_new_schema` 
if its value cannot be cast to the rewritten expression type.
   - Removes trivial equivalence classes after dropping such constants.
   - Propagates `UnionExec::compute_properties` errors from 
`UnionExec::try_new` instead of unwrapping.
   - Adds a regression test for union equivalence schema rewrite with an 
unrepresentable stale constant value.
   
   ## Are these changes tested?
   
   Yes:
   
   - `cargo fmt --all -- --check`
   - `cargo test -p datafusion-physical-expr 
test_union_drops_unrepresentable_constant_value_after_schema_rewrite -- 
--nocapture`
   - `cargo test -p datafusion-physical-plan union::tests::test_union -- 
--nocapture`
   - `cargo clippy -p datafusion-physical-expr -p datafusion-physical-plan 
--all-targets -- -D warnings`
   
   ## Are there any user-facing changes?
   
   No API change. This prevents a planner panic for affected `UNION ALL` + 
filter + projection query shapes.
   


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