Repository navigation
fix: alias surviving union inputs after an empty input is removed - #27612
Adam-Alani wants to merge 1 commit into
Conversation
propagate_empty_relation kept the removed input's field names when two or more union inputs survived. Physical planning then asserted that each input's column name matched that projection.
|
Thanks @Adam-Alani, this looks like a solid fix that completes the positional alignment for multi-input unions following the empty-input elimination. I independently reproduced the issue against unpatched The failure is particularly visible when the branches aren't bare projections—for example, branches containing Without an outer expression, I also observed the output schema drifting to the surviving input's name. With this PR's One minor test observation: the added bare-projection SQL example can be masked by Thanks for addressing this edge case. |
Which issue does this PR close?
Rationale for this change
SELECT a FROM t WHERE false UNION ALL SELECT b FROM s UNION ALL SELECT c FROM ufails while creating a physical plan:propagate_empty_relationdrops 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_schemanow expects the positional aliases.propagate_union_multiple_remaining_inputs_with_other_namescovers two surviving inputs with different names.union.sltexecutes theUNION ALLandUNIONforms.cargo test -p datafusion-optimizer --lib propagate_unionpasses 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.