Skip to content

[SQL] Implement (partially) FIRST_VALUE and LAST_VALUE window aggregation functions#3924

Merged
mihaibudiu merged 1 commit intomainfrom
issue3918
Apr 23, 2025
Merged

[SQL] Implement (partially) FIRST_VALUE and LAST_VALUE window aggregation functions#3924
mihaibudiu merged 1 commit intomainfrom
issue3918

Conversation

@mihaibudiu
Copy link
Copy Markdown
Contributor

We support FIRST_VALUE and LAST_VALUE only if they are used with an UNLIMITED RANGE.
This is still useful, because FIRST_VALUE is generated by the Calcite decorrelator when decorrelating queries that contain (ORDER BY ... LIMIT 1). This enables us to support such queries.

This partially fixes #3918.

Testing this has uncovered some bugs related to the sorting of NULL values and the handling of NULLS LAST and NULLS FIRST. Some tests were passing although they were incorrect, because they were tested on a system where NULLs compare largest. In our SQL dialect NULLs compare smallest (conveniently matches Rust, and cannot be easily changed).

We will write more tests for sorting as part of #3922

@mihaibudiu mihaibudiu changed the title [SQL] Implement (partially) FIRST_VALUE and LAST_VALUE window aggregation functions [SQL] Implement (partially) FIRST_VALUE and LAST_VALUE window aggregation functions Apr 23, 2025
…tion functions

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu mihaibudiu enabled auto-merge April 23, 2025 21:43
@mihaibudiu mihaibudiu added this pull request to the merge queue Apr 23, 2025
Merged via the queue into main with commit 820bebb Apr 23, 2025
2 checks passed
@mihaibudiu mihaibudiu deleted the issue3918 branch April 23, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SQL] Support FIRST_VALUE, LAST_VALUE window aggregate functions

2 participants