Strip table qualifiers from schema in UNION ALL
for unparser
#11082
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 oftable1.foo
.This came up as an issue when trying to validate the unparser works correctly for UNION ALL statements, which I added in #10603
Slightly modifying the above example, if I add an ORDER BY clause to the input SQL:
Then the resulting unparsed SQL will be:
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 was to remove the table qualifiers when building the Union plan directly, but that caused issues documented here: #10707 (comment)
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