phillipleblanc opened a new pull request, #11082: URL: https://github.com/apache/datafusion/pull/11082
## 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. This is my second attempt to fix #10706, my [first attempt](https://github.com/apache/datafusion/pull/10707) was to remove the table qualifiers when building the Union plan directly, but that caused issues documented here: https://github.com/apache/datafusion/pull/10707#discussion_r1618338309 This attempt scopes the problem to just removing the table qualifiers during the unparsing. ## What changes are included in this PR? Rewrite the LogicalPlan before unparsing to remove table identifiers from the Union All plan and any sort expressions that take a Union All plan as input. ## Are these changes tested? Yes, I added a test 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: [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]
