zhuqi-lucas opened a new pull request, #26400: URL: https://github.com/apache/datafusion/pull/26400
## Which issue does this PR close? - Closes #26364. ## Rationale for this change `OVER (w ROWS BETWEEN ...)` silently dropped the named window `w`. The planner only resolved `OVER w`; for a name inside the parentheses it ignored `WindowSpec::window_name`, so the window kept the frame but lost `w`'s `PARTITION BY` and `ORDER BY` and produced wrong results without an error. ## What changes are included in this PR? `match_window_definitions` now resolves a named window referenced inside `OVER (...)` the way the SQL standard and PostgreSQL do: - The window copies the referenced window's `PARTITION BY` and `ORDER BY`, and adds its own frame. - It may add an `ORDER BY` only when the referenced window has none. - It is an error to add a `PARTITION BY`, to override an existing `ORDER BY`, or to copy a window that has a frame. A window definition can also reference an earlier definition, such as `WINDOW w2 AS (w1 ROWS ...)`. Only earlier definitions can be referenced, so references cannot form a cycle. ## What is the testing strategy for this PR? New cases in `window.slt` cover inheriting with an added frame, adding an `ORDER BY`, a definition that references an earlier one, `OVER (w)`, and each error. All of them fail without the fix. ## Are there any user-facing changes? Queries that used `OVER (w ...)` now return correct results. Queries that relied on the old behavior to override `w`'s `PARTITION BY` or `ORDER BY` now get a planning error, as in PostgreSQL. -- 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]
