Skip to main content

sum_interval_counted

Function sum_interval_counted 

Source
fn sum_interval_counted<'a, I>(datums: I) -> Datum<'a>
where I: IntoIterator<Item = (Datum<'a>, Diff)>,
Expand description

Count-aware interval sum. Accumulates Σ value·diff per interval component in i128, which matches Accum::Interval in mz_compute::render::reduce; the narrowing back to the Interval field widths reproduces that variant’s finalize_accum arm. Consuming the multiplicity directly keeps this linear in the number of distinct values and correct for negative diffs (retractions), which expand_counts would silently drop.

A sum whose components exceed the Interval field widths is a query error only where the aggregate renders as an accumulable reduce, because that is the only rendering that pairs finalize_accum with AccumulableErrorCheck. This function and finalize_accum both return a bare Datum, so every other caller (constant folding, and window aggregates, which arrive through eval for whole-partition frames and through AccumulableOneByOneAggr otherwise) yields Datum::Null on overflow, which a reader cannot tell apart from an all-null input. SumUInt* has the same split today for negative accumulations. Closing it means giving aggregate evaluation an error channel.

Returns Datum::Null when no non-null value was accumulated, matching finalize_accum’s null handling: its is_zero check on Accum::Interval requires all three running sums and the non-null count to be zero.