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

Function expand_counts

src/expr/src/relation/func.rs:2014–2022  ·  view source on GitHub ↗

Expands an iterator of `(datum, diff)` into one `datum` per unit of `diff`. A non-positive `diff` contributes no copies. This is used by aggregates that are sensitive to multiplicity (e.g. `sum`), to recover a flat datum stream from the count-aware surface.

(datums: I)

Source from the content-addressed store, hash-verified

2012/// are sensitive to multiplicity (e.g. `sum`), to recover a flat datum stream
2013/// from the count-aware surface.
2014fn expand_counts<'a, I>(datums: I) -> impl Iterator<Item = Datum<'a>>
2015where
2016 I: IntoIterator<Item = (Datum<'a>, Diff)>,
2017{
2018 datums.into_iter().flat_map(|(datum, diff)| {
2019 let copies = usize::try_from(diff.into_inner()).unwrap_or(0);
2020 std::iter::repeat(datum).take(copies)
2021 })
2022}
2023
2024impl AggregateFunc {
2025 /// Whether this aggregate's result is independent of the multiplicity of its

Callers 3

evalMethod · 0.85
eval_with_unnest_listMethod · 0.85

Calls 4

flat_mapMethod · 0.45
into_iterMethod · 0.45
into_innerMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected