Adam-Alani opened a new pull request, #27612:
URL: https://github.com/apache/datafusion/pull/27612

   ## Which issue does this PR close?
   
   - Closes #27611.
   
   ## Rationale for this change
   
   `SELECT a FROM t WHERE false UNION ALL SELECT b FROM s UNION ALL SELECT c 
FROM u` fails while creating a physical plan:
   
   ```
   Assertion failed: col.name() == matching_name: Input field name b does not 
match with the projection expression a
   ```
   
   `propagate_empty_relation` drops the empty input and keeps the union schema, 
whose names came from that input. #26557 maps the remaining input by position 
when it is the only one left. When two or more inputs survive, the union is 
rebuilt with those names and the other inputs are left unchanged.
   
   ## What changes are included in this PR?
   
   When an empty union input is removed and more than one input remains, each 
surviving input whose field names differ from the union schema is wrapped in a 
projection that aliases its columns by position. Inputs that already use those 
names are left as they are. The single-remaining-input path uses the same 
projection helper.
   
   ## What is the testing strategy for this PR?
   
   - `propagate_union_children_different_schema` now expects the positional 
aliases.
   - `propagate_union_multiple_remaining_inputs_with_other_names` covers two 
surviving inputs with different names.
   - `union.slt` executes the `UNION ALL` and `UNION` forms.
   - `cargo test -p datafusion-optimizer --lib propagate_union` passes locally.
   
   ## Are there any user-facing changes?
   
   Queries that previously failed to plan now return rows. Plans whose 
remaining inputs already share the union's field names are unchanged.
   


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