Skip to content

[SQL] Compile SQL window ROWS queries to RANGE (ROW_NUMBER)#6613

Merged
mihaibudiu merged 1 commit into
feldera:mainfrom
mihaibudiu:issue5908
Jul 15, 2026
Merged

[SQL] Compile SQL window ROWS queries to RANGE (ROW_NUMBER)#6613
mihaibudiu merged 1 commit into
feldera:mainfrom
mihaibudiu:issue5908

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This PR implements support for window queries like

SELECT empno, SUM(sal) OVER (
PARTITION BY deptno ORDER BY empno
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS s

Previously we only supported RANGE queries, but not ROWS queries.

There is no native DBSP operator that implements ROWS BETWEEN, so this is done by rewriting the SQL to first compute a ROW_NUMBER for each partition and use that in evaluating the BETWEEN clause using a RANGE query. This rewrite is done purely at the Calcite level.

ROW_NUMBER is not the most efficient operator, so this many not work great for all use cases. It is still TBD whether native support for ROWS can do better.

With this change we support all 100 TPC-DS queries.

Fixes #5908

Describe Manual Test Plan

Ran java tests manually.

Checklist

  • Unit tests added/updated
  • Documentation updated

@mihaibudiu mihaibudiu changed the title [SQL] Compile SQL window ROWS queries to RANGE (ROW_NUMBER) [SQL] Compile SQL window ROWS queries to RANGE (ROW_NUMBER) Jul 10, 2026
@mihaibudiu

Copy link
Copy Markdown
Contributor Author

Most of the changes are just new tests.

</tr>
</table>

:::warning Potential inefficiency

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.

This paragraph was moved down in the file

@mythical-fred mythical-fred left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@mihaibudiu
mihaibudiu requested a review from gz July 15, 2026 17:04
@mihaibudiu
mihaibudiu added this pull request to the merge queue Jul 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 15, 2026
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu
mihaibudiu enabled auto-merge July 15, 2026 20:58
@mihaibudiu
mihaibudiu added this pull request to the merge queue Jul 15, 2026
Merged via the queue into feldera:main with commit 393fac9 Jul 15, 2026
1 check passed
@mihaibudiu
mihaibudiu deleted the issue5908 branch July 15, 2026 23:44
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][DBSP] Consider whether we can support OVER (ROWS BETWEEN ...) queries

3 participants