Skip to content

feat: Framing for FIRST_VALUE, LAST_VALUE. - #19301

Merged
gianm merged 5 commits into
apache:masterfrom
gianm:sql-window-flv-frames
Aug 19, 2026
Merged

gianm merged 5 commits into
apache:masterfrom
gianm:sql-window-flv-frames

Conversation

@gianm

@gianm gianm commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

This patch implements framing support for the FIRST_VALUE, LAST_VALUE window functions and updates all relevant tests. New tests are also added for the processors themselves.

This patch implements framing support for the FIRST_VALUE, LAST_VALUE
window functions and updates all relevant tests. New tests are also
added for the processors themselves.
return;
}

final WindowFrame.Groups groupsFrame = frame.unwrap(WindowFrame.Groups.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Bounded RANGE frames still execute with GROUPS semantics

The new framed path treats every non-ROWS frame as WindowFrame.Groups, and Windowing maps Calcite's isRows == false windows into that representation. That is not correct for bounded SQL RANGE frames, which must use value-distance on the ORDER BY expression. Queries like FIRST_VALUE(x) OVER (ORDER BY t RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) will still return wrong answers even though this PR now enables framed FIRST_VALUE/LAST_VALUE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processing won't get this far due to validation. There's a test for it in CalciteQueryTest#testUnSupportedRangeBounds, expecting an error message like:

Order By with RANGE clause currently supports only UNBOUNDED or CURRENT ROW.

I added a comment here about that.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes LGTM, no correctness issues found.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jun 27, 2026
@github-actions

Copy link
Copy Markdown

This pull request/issue has been closed due to lack of activity. If you think that
is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Jul 26, 2026
@gianm gianm reopened this Jul 30, 2026
@gianm gianm removed the stale label Jul 30, 2026

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 79 of 79 changed files. The original bounded RANGE concern is fixed on the SQL path because validation rejects offset-based non-ROWS frames before the GROUPS-based implementation. No additional high-confidence PR-caused issues found.


This is an automated review by Codex GPT-5.6-Luna(max)

@gianm
gianm merged commit 4766794 into apache:master Aug 19, 2026
28 checks passed
@gianm
gianm deleted the sql-window-flv-frames branch August 19, 2026 23:26
@github-actions github-actions Bot added this to the 39.0.0 milestone Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants