kosiew opened a new pull request, #22683:
URL: https://github.com/apache/datafusion/pull/22683
## Which issue does this PR close?
* Part of #22668
## Rationale for this change
The SQL unparser currently determines when a logical plan must preserve an
independent `SELECT` scope in multiple places, with different operator sets
depending on context. While those differences are intentional, the underlying
rationale is not centralized or documented, making future changes harder to
reason about.
This PR adds characterization tests for the current behavior and introduces
a single helper that makes the context-specific boundary decisions explicit
without changing generated SQL.
## What changes are included in this PR?
* Introduce a private `SelectScopeContext` enum to describe the two
select-scope boundary contexts:
* `WindowInput`
* `SubqueryAliasChild`
* Add a centralized helper:
* `plan_requires_independent_select_scope(plan, context)`
* Refactor:
* `window_input_requires_derived_subquery()`
* `requires_derived_subquery()`
so they delegate to the new helper while preserving existing behavior.
* Add characterization tests covering `SubqueryAlias` children that must
remain derived:
* aggregate child
* window child
* sort child
* limit child
* union child
* Add characterization tests covering `Window` inputs that must remain
derived:
* sort input
* union input
* Add a shared helper for constructing `ROW_NUMBER()` window expressions
used by the new tests.
No SQL output changes are intended by this refactor.
## Are these changes tested?
Yes.
New tests added in `datafusion/sql/tests/cases/plan_to_sql.rs`:
* `test_unparse_subquery_alias_select_scope_boundaries`
* `test_unparse_window_over_sort_without_projection`
* `test_unparse_window_over_union_without_projection`
These tests validate the current derived-subquery boundary behavior and
ensure the refactor remains behavior-preserving.
## Are there any user-facing changes?
No.
This change is a refactor and test expansion that preserves existing SQL
generation behavior and does not introduce user-facing functionality changes.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content
has been manually reviewed and tested.
--
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]