Skip to main content

Module window_builtins

Module window_builtins 

Source
Expand description

Built-in window functions (S13.5, bd-14i6).

Implements: row_number, rank, dense_rank, percent_rank, cume_dist, ntile, lag, lead, first_value, last_value, nth_value, plus aggregate-as-window variants including group_concat and string_agg.

These functions implement the WindowFunction trait. The VDBE is responsible for partitioning, ordering, and frame management; these implementations provide the per-row computation logic.

§Design Notes

Pure-numbering functions (row_number, rank, dense_rank) track position via step() and expose the current value through value(). The ORDER BY column is passed as args[0] so the function can detect peer-group boundaries.

Buffer-based functions (lag, lead, first_value, last_value, nth_value) maintain an internal VecDeque of values and expose frame-relative access through value().

Structs§

CumeDistFunc
CumeDistState
State for cume_dist().
DenseRankFunc
DenseRankState
FirstValueFunc
FirstValueState
LagFunc
LagState
State for lag(): maintains a buffer of previous values.
LastValueFunc
LastValueState
LeadFunc
LeadState
State for lead(): maintains a buffer and reads ahead.
NthValueFunc
NthValueState
NtileFunc
NtileState
State for ntile(N).
PercentRankFunc
PercentRankState
State for percent_rank().
RankFunc
RankState
RowNumberFunc
RowNumberState
WindowAvgFunc
WindowAvgState
WindowCountFunc
WindowCountState
WindowGroupConcatFunc
WindowGroupConcatState
WindowMaxFunc
WindowMaxState
WindowMinFunc
WindowMinState
WindowStringAggFunc
WindowSumFunc
WindowSumState
WindowTotalFunc

Functions§

cmp_values
Compare two SQLite values using type-aware ordering.
register_window_builtins
Register all S13.5 window functions.