Skip to main content

sum_signed_int_counted

Function sum_signed_int_counted 

Source
fn sum_signed_int_counted<'a, I, N>(datums: I, narrow: N) -> Datum<'a>
where I: IntoIterator<Item = (Datum<'a>, Diff)>, N: FnOnce(i128) -> Datum<'a>,
Expand description

Count-aware signed-integer sum. Accumulates Σ value·diff in i128, which matches the width of the dataflow’s Accum::SimpleNumber accumulator (see build_accumulable and finalize_accum in mz_compute::render::reduce); narrow then reproduces that variant’s finalize_accum arm. Unlike expand_counts, this consumes the multiplicity directly, so it is linear in the number of distinct values and correct for negative diffs (retractions), which expand_counts would silently drop.

Returns Datum::Null when no non-null value was accumulated, matching finalize_accum’s null handling: its is_zero check on SimpleNumber requires both a zero running sum and a zero non-null count.