You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window referencing a named window with an added frame, OVER (w ROWS ...), silently drops PARTITION BY and ORDER BY #26364
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;
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
Resolve named windows referenced inside OVER (...) (apache#26400)