apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
6.34k stars 1.2k forks source link

fix: Remove dangling table references in `unparser` #13405

Open peasee opened 1 week ago

peasee commented 1 week ago

Which issue does this PR close?

Closes #13027

Rationale for this change

This change ensures that table references which don't exist at their current level are removed. For example, SELECT ta.j1_id FROM (SELECT j1_id FROM j1 ta) is invalid because the subquery is un-aliased so ta is not a valid reference at the top-level projection.

This is usually caused by derived subqueries, both un-aliased and aliased.

What changes are included in this PR?

Are these changes tested?

Yes. A collection of new plan-to-SQL roundtrip tests to validate the changes.

Are there any user-facing changes?

No