MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / sum_datum

Function sum_datum

src/expr/src/relation/func.rs:116–132  ·  view source on GitHub ↗
(datums: I)

Source from the content-addressed store, hash-verified

114}
115
116fn sum_datum<'a, I, DatumType, ResultType>(datums: I) -> Datum<'a>
117where
118 I: IntoIterator<Item = Datum<'a>>,
119 DatumType: TryFrom<Datum<'a>>,
120 <DatumType as TryFrom<Datum<'a>>>::Error: std::fmt::Debug,
121 ResultType: From<DatumType> + Sum + Into<Datum<'a>>,
122{
123 let mut datums = datums.into_iter().filter(|d| !d.is_null()).peekable();
124 if datums.peek().is_none() {
125 Datum::Null
126 } else {
127 let x = datums
128 .map(|d| ResultType::from(DatumType::try_from(d).expect("unexpected type")))
129 .sum::<ResultType>();
130 x.into()
131 }
132}
133
134/// Count-aware signed-integer sum. Accumulates `Σ value·diff` in `i128`, which
135/// matches the width of the dataflow's `Accum::SimpleNumber` accumulator (see

Callers

nothing calls this directly

Calls 7

is_noneMethod · 0.80
expectMethod · 0.80
filterMethod · 0.45
into_iterMethod · 0.45
is_nullMethod · 0.45
peekMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected