MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / reduce_agg_partials

Function reduce_agg_partials

nodedb-cluster/src/distributed_array/merge.rs:134–146  ·  view source on GitHub ↗

Merge per-shard partial aggregates into one result per group-by key. Groups by `group_key`; uses `ArrayAggPartial::merge` for each group.

(shard_resps: &[ArrayShardAggResp])

Source from the content-addressed store, hash-verified

132///
133/// Groups by `group_key`; uses `ArrayAggPartial::merge` for each group.
134pub fn reduce_agg_partials(shard_resps: &[ArrayShardAggResp]) -> Vec<ArrayAggPartial> {
135 use std::collections::BTreeMap;
136 let mut buckets: BTreeMap<i64, ArrayAggPartial> = BTreeMap::new();
137 for resp in shard_resps {
138 for partial in &resp.partials {
139 buckets
140 .entry(partial.group_key)
141 .and_modify(|existing| existing.merge(partial))
142 .or_insert_with(|| partial.clone());
143 }
144 }
145 buckets.into_values().collect()
146}
147
148#[cfg(test)]
149mod tests {

Callers 7

reduce_sum_across_shardsFunction · 0.85
reduce_min_across_shardsFunction · 0.85
reduce_max_across_shardsFunction · 0.85
coord_aggMethod · 0.85

Calls 4

entryMethod · 0.80
collectMethod · 0.80
mergeMethod · 0.45
cloneMethod · 0.45

Tested by 6

reduce_sum_across_shardsFunction · 0.68
reduce_min_across_shardsFunction · 0.68
reduce_max_across_shardsFunction · 0.68