Skip to content

feat: add window function support#375

Merged
KKould merged 6 commits into
mainfrom
feat/window-functions
Jul 12, 2026
Merged

feat: add window function support#375
KKould merged 6 commits into
mainfrom
feat/window-functions

Conversation

@KKould

@KKould KKould commented Jul 12, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

KiteSQL cannot currently bind or execute SQL window functions, so queries that need ranking or partition-level aggregate results are rejected.

Issue link: N/A

What is changed and how it works?

  • Adds binding, logical and physical planning, optimization, execution, and serialization for window functions.
  • Supports ROW_NUMBER, RANK, DENSE_RANK, and COUNT/SUM/AVG/MIN/MAX with OVER.
  • Separates window functions from their partition and ordering specification. Functions sharing a specification use one Window operator; different specifications produce separate Sort and Window layers.
  • Reuses the existing Sort executor for window ordering and aggregate accumulators for aggregate window functions.
  • Buffers and reuses only the current partition during execution.
  • Adds explicit ORM APIs for the supported window functions.
  • Rejects explicit frames, named windows, and QUALIFY as unsupported instead of silently accepting them.

Code changes

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

The coverage includes ranking and aggregate functions, peer rows, null values, shared and different window specifications, duplicate calls, grouped aggregates feeding windows, View round trips, unsupported syntax, and Explain plans.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

Window functions with the same specification are evaluated together. A change in PARTITION BY or window ORDER BY creates another Sort and Window layer.

@KKould KKould self-assigned this Jul 12, 2026
@KKould KKould added the enhancement New feature or request label Jul 12, 2026
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.79390% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.84%. Comparing base (362157d) to head (692aef6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/binder/parser.rs 93.47% 6 Missing ⚠️
src/binder/window.rs 96.10% 6 Missing ⚠️
src/planner/mod.rs 0.00% 6 Missing ⚠️
src/expression/window.rs 77.77% 4 Missing ⚠️
src/planner/operator/window.rs 84.61% 4 Missing ⚠️
src/expression/evaluator.rs 0.00% 3 Missing ⚠️
src/expression/mod.rs 95.52% 3 Missing ⚠️
src/execution/dql/window/function.rs 97.22% 2 Missing ⚠️
src/binder/aggregate.rs 95.00% 1 Missing ⚠️
src/binder/select.rs 95.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #375      +/-   ##
==========================================
+ Coverage   92.74%   92.84%   +0.10%     
==========================================
  Files         243      249       +6     
  Lines       41025    41790     +765     
==========================================
+ Hits        38049    38802     +753     
- Misses       2976     2988      +12     
Flag Coverage Δ
rust 92.84% <95.79%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/binder/expr.rs 94.42% <100.00%> (-0.21%) ⬇️
src/binder/mod.rs 85.52% <ø> (ø)
src/db.rs 92.90% <100.00%> (+<0.01%) ⬆️
src/execution/dql/aggregate/hash_agg.rs 95.36% <100.00%> (+0.03%) ⬆️
src/execution/dql/aggregate/min_max.rs 96.29% <100.00%> (+5.82%) ⬆️
src/execution/dql/aggregate/simple_agg.rs 89.58% <100.00%> (+0.22%) ⬆️
src/execution/dql/aggregate/sum.rs 100.00% <100.00%> (+23.52%) ⬆️
src/execution/dql/mod.rs 100.00% <ø> (ø)
src/execution/dql/window.rs 100.00% <100.00%> (ø)
src/execution/mod.rs 95.09% <100.00%> (+0.05%) ⬆️
... and 26 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KKould KKould merged commit c19209e into main Jul 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant