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

   Title: Fix DuckDB unparse for optimized join projections
   
   ## Which issue does this PR close?
   
   - Closes #22961.
   
   ## Rationale for this change
   
   Optimized plans can introduce intermediate projection aliases from common 
subexpression elimination and can also leave join conditions referencing 
aliases from a flattened join input.
   
   The SQL unparser was rebasing some unqualified optimizer aliases to a table 
alias, producing invalid references such as `"o"."__common_expr_1"`. It could 
also emit a derived projection around a join input while the outer join 
condition still referenced aliases inside that derived table, producing SQL 
that DuckDB rejects.
   
   ## What changes are included in this PR?
   
   - Make `TableAliasRewriter` use `DFSchema` qualifier information instead of 
only Arrow field names, with explicit control over whether unqualified fields 
should be rebound to a table alias.
   - Keep existing alias rebasing for table-scan filters and window-derived 
inputs.
   - Avoid wrapping qualified pass-through join projections when they are used 
as the left input of another already projected join, so referenced aliases 
remain in scope.
   - Add a regression test for the optimized DuckDB unparse path from the issue.
   
   ## Are these changes tested?
   
   - `cargo fmt --all`
   - `cargo test -p datafusion --test core_integration 
optimized_duckdb_unparse_preserves_derived_table_scope`
   - `cargo test -p datafusion-sql --test sql_integration`
   - `cargo test -p datafusion-sql unparser::rewrite`
   - `cargo clippy -p datafusion-sql --test sql_integration -- -D warnings`
   - `cargo clippy -p datafusion --test core_integration -- -D warnings`
   
   ## Are there any user-facing changes?
   
   No public API changes. This fixes SQL generated by the unparser for 
optimized logical plans.


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