blinding-pixels opened a new pull request, #24808:
URL: https://github.com/apache/datafusion/pull/24808

   ## Which issue does this PR close?
   
   - Closes #13027.
   
   ## Rationale for this change
   
   I noticed that this issue had an earlier PR from almost two years ago. That 
implementation was closed because it used broad identifier cleanup, and 
maintainers were concerned it could introduce subtle bugs.
   
   Since then, DataFusion has added much of the machinery needed for the 
approaches recommended in that review. This solution uses that newer machinery 
and combines both approaches. It removes the qualifier when the derived table 
does not need an alias, and rewrites the reference to the derived alias when 
the dialect requires one.
   
   ## What changes are included in this PR?
   
   This PR detects when a projection enters a new derived-table scope and 
prevents its outer expressions from referring to an inner table alias that is 
no longer visible.
   
   For dialects that do not require a derived-table alias, the invalid inner 
qualifier is removed. For dialects such as MySQL that require an alias, the 
outer reference is rewritten to the generated derived-table alias. Explicitly 
named subquery scopes remain unchanged.
   
   ## What is the testing strategy for this PR?
   
   The SQL unparser round-trip tests cover the issue's original query with both 
the generic and MySQL dialects. They also cover filtered and distinct derived 
inputs, and update existing limit and nested-projection cases to assert valid 
outer references.
   
   The required formatting, Clippy, and extended workspace test suite all pass, 
including all 505 SQL logic test files.
   
   ## Are there any user-facing changes?
   
   Yes. SQL produced by the unparser no longer contains qualifiers that refer 
to tables outside their visible scope. Dialects that require derived-table 
aliases now qualify the outer reference with the generated alias. There are no 
public API changes.
   


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