phillipleblanc opened a new pull request, #10707: URL: https://github.com/apache/datafusion/pull/10707
## Which issue does this PR close? Closes #10706 ## Rationale for this change The schema that is the result of a UNION ALL should not have any table qualifiers, as the table information has effectively been erased and is no longer a valid reference. Consider the following SQL: ```sql SELECT table1.foo FROM table1 UNION ALL SELECT table2.foo FROM table2 ``` The logical schema from this UNION ALL should be just `foo`, but it is currently taking the first input's schema directly, resulting in a schema of `table1.foo`. This came up as an issue when trying to validate the unparser works correctly for UNION ALL statements, which I added in https://github.com/apache/datafusion/pull/10603 Slightly modifying the above example, if I add an ORDER BY clause to the input SQL: ```sql SELECT table1.foo FROM table1 UNION ALL SELECT table2.foo FROM table2 ORDER BY foo ``` Then the resulting unparsed SQL will be: ```sql SELECT table1.foo FROM table1 UNION ALL SELECT table2.foo FROM table2 ORDER BY table1.foo ``` Because the unparser takes the schema directly from the Union node when writing out the column expressions. ## What changes are included in this PR? Fixes the `LogicalPlanBuilder::union` to not take the first input's schema directly, but sets it to `None`. ## Are these changes tested? Yes, I added a test both in the LogicalPlanBuilder and in the Unparser `sql_integration` test. ## Are there any user-facing changes? No -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org