Expand description
SQL:2003 window-function evaluation kernel.
This module implements a self-contained window-evaluation engine over an
already-materialized set of rows. It is intentionally decoupled from the SQL
parser/planner: callers drive it directly by constructing a WindowFunction
and a WindowSpec, then calling evaluate_window (closure-driven) or
evaluate_window_batch (over a RecordBatch).
§Supported functions
ROW_NUMBER()— sequential 1-based ordinal within each partition.RANK()— competition ranking: equal order keys share a rank and the next distinct key skips ranks (1, 1, 3, ...).DENSE_RANK()— likeRANK()but without gaps (1, 1, 2, ...).LAG(expr[, offset[, default]])— value ofexproffsetrows before the current row inside the sorted partition; out-of-range yields the supplied default orNULL.LEAD(expr[, offset[, default]])— symmetric toLAGbut forward.FIRST_VALUE(expr)/LAST_VALUE(expr)— first / last value ofexprin the sorted partition.NTH_VALUE(expr, n)— then-th (1-based) value ofexprin the sorted partition, orNULLwhen the partition has fewer thannrows.
§Row model
The crate stores data column-by-column (RecordBatch / ColumnData),
so there is no concrete “row” struct to borrow. The kernel therefore
addresses values by (row_index, column_index) pairs and pulls them through
a value_at closure. Column indices in WindowSpec and the target_column
arguments are positions into that columnar model, exactly as in
crate::executor::aggregate and crate::executor::sort.
§Value ordering
Ordering follows the same rules as crate::executor::sort: real values
compare naturally, NULLs sort after non-NULLs in ascending order, and a
descending OrderKey simply reverses the per-key ordering. Numeric values
of differing widths are compared after promotion (matching the coercion used
by crate::executor::filter). The comparison never assumes the full set of
Value variants, so newer variants degrade gracefully to “equal”.
Structs§
- Order
Key - A single
ORDER BYkey inside anOVER (... ORDER BY ...)clause. - Window
Spec - The
OVER (PARTITION BY ... ORDER BY ...)specification.
Enums§
- Window
Function - A window function to evaluate over partitioned, ordered rows.
Functions§
- evaluate_
window - Evaluate a window function over
num_rowsrows. - evaluate_
window_ batch - Evaluate a window function directly over a
RecordBatch.