fix(sql): reject duplicate unqualified names in CTAS, CREATE VIEW, and SELECT INTO#22290
Open
kumarUjjawal wants to merge 1 commit into
Open
fix(sql): reject duplicate unqualified names in CTAS, CREATE VIEW, and SELECT INTO#22290kumarUjjawal wants to merge 1 commit into
kumarUjjawal wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
Rationale for this change
CREATE TABLE AS,CREATE VIEW, andSELECT INTOcan persist only plaincolumn names.
Before this change, a query like a self join could produce qualified output
columns such as
x.column1andy.column1, which are valid while planning.But when the table or view was created, those qualifiers were dropped and the
stored schema became
column1,column1, ... with duplicates.That meant the create step succeeded, but the created table or view failed
later when the user tried to read from it. The object existed in the catalog
but was not usable.
This PR fixes that by rejecting these cases during planning, before the table
or view is created.
What changes are included in this PR?
This PR adds a shared SQL planner check that validates the final output schema
has unique unqualified column names.
It applies that check to:
CREATE TABLE ASCREATE VIEWSELECT INTOThe check runs after the final projection or aliasing step, so it validates the
actual names that would be stored.
This PR also adds sqllogictest coverage for the duplicate-column self-join case
for all three flows.
Are these changes tested?
Yes
Are there any user-facing changes?
Invalid
CREATE TABLE AS,CREATE VIEW, andSELECT INTOstatements thatwould create an object with duplicate unqualified column names now fail early
during planning with a schema error, instead of succeeding and creating an
unreadable table or view.
No API Changes