Skip to main content

Module window

Module window 

Source
Expand description

Window Function FFI for JIT

External C functions for SQL-style window functions called from JIT-compiled code. Window functions require partition and ordering context, so these FFI functions operate on pre-computed partition data passed from the query executor.

Functionsยง

jit_window_avg
AVG() over window frame Args: running_sum, count
jit_window_count
COUNT() over window frame Args: count (pre-computed count over frame)
jit_window_dense_rank
DENSE_RANK() - Returns rank without gaps for ties Args: current_idx, partition_size Note: Simplified - assumes ORDER BY already applied and no ties
jit_window_first_value
FIRST_VALUE(expr) - Returns first value in the window frame
jit_window_frame_end
Calculate frame end index Args: current_idx, following (n following or -1 for unbounded), partition_size
jit_window_frame_start
Calculate frame start index Args: current_idx, preceding (n preceding or -1 for unbounded)
jit_window_lag
LAG(value, offset) - Returns value from offset rows before current Args: current_value, offset, default_value, is_valid (1 if in bounds, 0 if out)
jit_window_last_value
LAST_VALUE(expr) - Returns last value in the window frame
jit_window_lead
LEAD(value, offset) - Returns value from offset rows after current Args: current_value, offset, default_value, is_valid (1 if in bounds, 0 if out)
jit_window_max
MAX() over window frame Args: running_max (pre-computed max over frame)
jit_window_min
MIN() over window frame Args: running_min (pre-computed min over frame)
jit_window_nth_value
NTH_VALUE(expr, n) - Returns nth value in the window frame Args: nth_value, is_valid (1 if nth exists, 0 if not)
jit_window_ntile
NTILE(n) - Distributes rows into n buckets Args: current_idx, partition_size, num_buckets
jit_window_rank
RANK() - Returns rank with gaps for ties Args: current_idx, partition_size Note: Simplified - assumes ORDER BY already applied and no ties
jit_window_row_number
ROW_NUMBER() - Returns sequential row number within partition Args: current_idx (0-based position in partition)
jit_window_sum
SUM() over window frame Args: running_sum (pre-computed sum over frame)