Skip to content

Window referencing a named window with an added frame, OVER (w ROWS ...), silently drops PARTITION BY and ORDER BY #26364

Closed

Description

@zhuqi-lucas

Describe the bug

A window that references a named window and adds a frame, such as OVER (w ROWS BETWEEN ...), keeps the frame but silently drops the named window's PARTITION BY and ORDER BY. The function then runs over all rows as one partition, so values leak across partitions. There is no error.

OVER w works. Only the form with the name inside the parentheses is affected.

To Reproduce

CREATE TABLE t(ticker VARCHAR, ts INT, price DOUBLE) AS VALUES
  ('BTC', 1, 100.0), ('BTC', 2, 105.0), ('BTC', 3, 102.0),
  ('DOGE', 1, 0.1), ('DOGE', 2, 0.2), ('DOGE', 3, 0.15);

SELECT ticker, ts, price,
  MAX(price) OVER (w ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS named_plus_frame,
  MAX(price) OVER (PARTITION BY ticker ORDER BY ts ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS inline
FROM t
WINDOW w AS (PARTITION BY ticker ORDER BY ts)
ORDER BY ticker, ts;
+--------+----+-------+------------------+--------+
| ticker | ts | price | named_plus_frame | inline |
+--------+----+-------+------------------+--------+
| BTC    | 1  | 100.0 | 100.0            | 100.0  |
| BTC    | 2  | 105.0 | 105.0            | 105.0  |
| BTC    | 3  | 102.0 | 105.0            | 105.0  |
| DOGE   | 1  | 0.1   | 102.0            | 0.1    |
| DOGE   | 2  | 0.2   | 0.2              | 0.2    |
| DOGE   | 3  | 0.15  | 0.2              | 0.2    |
+--------+----+-------+------------------+--------+

The first DOGE row gets BTC's price (102.0).

Expected behavior

OVER (w ROWS BETWEEN ...) should inherit w's PARTITION BY and ORDER BY and add the frame, as in the SQL standard and PostgreSQL, so both columns above match. Per the standard (and PostgreSQL), it should be an error if the referencing window also specifies PARTITION BY, specifies ORDER BY when w already has one, or if w itself has a frame.

Additional context

match_window_definitions in datafusion/sql/src/select.rs only rewrites WindowType::NamedWindow (OVER w). For OVER (w ...), sqlparser produces a WindowType::WindowSpec with window_name = Some(w), and window_name is never read when planning, so w is dropped. A WINDOW w2 AS (w1 ...) definition that references another window likely has the same problem.

Reproduced with datafusion-cli ; the same code path is unchanged on main.

Activity

  1. self-assigned this
    on Oct 15, 2026
  2. added a commit that references this issue on Oct 20, 2026
    6131a98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions