alexanderbianchi opened a new pull request, #27188: URL: https://github.com/apache/datafusion/pull/27188
## Which issue does this PR close? Related to #18818: preserve column names when inserting casts. ## Rationale for this change UNION type coercion can reject two distinct joined columns with `Schema contains duplicate unqualified field name a`: ```sql SELECT 1::BIGINT AS a, 2::BIGINT AS b UNION ALL SELECT x.a, y.a FROM (VALUES (3::INT)) AS x(a) CROSS JOIN (VALUES (4::INT)) AS y(a); ``` The inserted casts retain the name `a` but drop the qualifiers `x` and `y`, creating a collision before UNION aligns the output names. The same problem affects SQL → Substrait → DataFusion round trips when nested nullability differences require casts. A plain struct reproduces it without NULL literals. ## What changes are included in this PR? Preserve a column's qualifier when adding a cast, and retain existing aliases, including their qualifiers and metadata. Output field names remain unchanged. ## What is the testing strategy for this PR? - SQL regression for joined integer columns under UNION. - Substrait round trips for plain structs without NULLs and map/list columns with typed NULLs; both failed before the fix and pass afterward. - Coverage for existing projections, newly inserted projections, and qualified aliases. Validation passed: 13,507 Rust tests, all 547 SQL logic-test files, `cargo fmt --all`, all-target/all-feature Clippy with warnings denied, and the repository submission lint checks. ## Are there any user-facing changes? Queries affected by the duplicate-field error now plan and execute. No public API changes. -- 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]
