patrickswedish opened a new pull request, #26390:
URL: https://github.com/apache/datafusion/pull/26390
## Which issue does this PR close?
- Closes #26364
## Rationale for this change
When a window references a named window with an added frame clause (e.g.
`OVER (w ROWS BETWEEN 1 PRECEDING AND CURRENT ROW)`), `sqlparser` produces
`WindowType::WindowSpec` with `window_name = Some(w)`. Previously,
`match_window_definitions` only checked for `WindowType::NamedWindow(ident)`
(`OVER w`), silently ignoring `spec.window_name`. Consequently, the named
window's `PARTITION BY` and `ORDER BY` were dropped, causing values to leak
across partitions.
## What changes are included in this PR?
1. Resolves named window specifications and handles inheritance for
`WindowType::WindowSpec` where `spec.window_name` is present.
2. Enforces SQL standard / PostgreSQL validation invariants:
- Forbids overriding `PARTITION BY` on a window referencing an existing
window (`Cannot override PARTITION BY clause of window {ident}`).
- Forbids overriding `ORDER BY` if the referenced base window already
specifies one (`Cannot override ORDER BY clause of window {ident}`).
- Forbids copying a window if the base window specifies an explicit frame
clause (`Cannot copy window {ident} because it has a frame clause`).
3. Supports chained named window specifications (e.g. `WINDOW w1 AS (...),
w2 AS (w1 ...)`).
4. Clears `window_name` once resolved so downstream planners receive
fully-resolved window specifications.
5. Extends resolution to cover `qualify` expressions as well as `projection`.
6. Adds comprehensive unit tests in `sql_integration.rs` and sqllogictest
cases in `window.slt`.
## Are these changes tested?
Yes:
- `cargo test -p datafusion-sql` (612 unit tests and 12 doctests pass)
- `cargo clippy -p datafusion-sql --all-targets` (clean with 0 warnings)
- `cargo fmt --check -p datafusion-sql` (clean)
---
*Diff minimization and pre-flight validation performed with [ZeroSlop™
CI](https://github.com/marketplace/actions/zeroslop-by-ribbsaeter-systems) —
[Ribbsaeter Systems](https://ribbsaetersystems.com/).*
--
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]