Skip to main content

Module agg

Module agg 

Source
Expand description

SQLR-3 aggregate runtime.

Three concerns live here:

  1. AggState — per-group accumulator state for COUNT/SUM/AVG/MIN/MAX, with SQLite-style numeric type rules (Sum stays Integer until a Real input or i64 overflow forces a one-time promotion to f64).
  2. DistinctKey — a hashable typed wrapper around Value, used both as the per-row key for GROUP BY and as the dedupe key for COUNT(DISTINCT col) and SELECT DISTINCT.
  3. like_match — the iterative two-pointer LIKE matcher (case insensitive ASCII to match SQLite’s default).

All of this is pure-functional in the sense that nothing here touches the Database/Table. The executor walks rows and feeds values in.

Enums§

AggState
Per-aggregate accumulator. One instance per (group, projection-slot) pair lives for the duration of the SELECT.
DistinctKey
A hashable typed wrapper around Value, used as the GROUP BY key element and as the COUNT(DISTINCT col) set entry. We can’t impl Hash for Value because Value has a Real(f64) variant and f64 isn’t Hash + Eq. Round-trip via f64::to_bits to keep the canonical bit-pattern as the key — NaN keys remain distinguishable by exact bit pattern, which is the safer choice for grouping (we don’t try to be cute about NaN==NaN).
SumAcc
SQLite-style numeric accumulator: stays Int while every input is Integer and the running total fits in i64, otherwise promotes once to Real and never demotes back.

Functions§

like_match
SQL LIKE matcher.