kumarUjjawal opened a new pull request, #22290:
URL: https://github.com/apache/datafusion/pull/22290

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Closes #22167 
   
   ## Rationale for this change
   
    `CREATE TABLE AS`, `CREATE VIEW`, and `SELECT INTO` can persist only plain
     column names.
   
     Before this change, a query like a self join could produce qualified output
     columns such as `x.column1` and `y.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.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.  
   -->
   
   ## 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 AS`
     - `CREATE VIEW`
     - `SELECT INTO`
   
     The 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.
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   Yes
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
     Invalid `CREATE TABLE AS`, `CREATE VIEW`, and `SELECT INTO` statements that
     would 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
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


-- 
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]

Reply via email to