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

Method merge

nodedb-array/src/query/aggregate.rs:62–112  ·  view source on GitHub ↗

Merge two partials of the same reducer kind. Mismatched reducers produce a left-biased result (the executor only ever merges same-kind partials, so this is a programming-error path).

(self, other: AggregateResult)

Source from the content-addressed store, hash-verified

60 /// reducers produce a left-biased result (the executor only ever
61 /// merges same-kind partials, so this is a programming-error path).
62 pub fn merge(self, other: AggregateResult) -> AggregateResult {
63 use AggregateResult::*;
64 match (self, other) {
65 (Empty(_), x) | (x, Empty(_)) => x,
66 (
67 Sum {
68 value: a,
69 count: ca,
70 },
71 Sum {
72 value: b,
73 count: cb,
74 },
75 ) => Sum {
76 value: a + b,
77 count: ca + cb,
78 },
79 (Count { count: a }, Count { count: b }) => Count { count: a + b },
80 (
81 Min {
82 value: a,
83 count: ca,
84 },
85 Min {
86 value: b,
87 count: cb,
88 },
89 ) => Min {
90 value: if a <= b { a } else { b },
91 count: ca + cb,
92 },
93 (
94 Max {
95 value: a,
96 count: ca,
97 },
98 Max {
99 value: b,
100 count: cb,
101 },
102 ) => Max {
103 value: if a >= b { a } else { b },
104 count: ca + cb,
105 },
106 (Mean { sum: a, count: ca }, Mean { sum: b, count: cb }) => Mean {
107 sum: a + b,
108 count: ca + cb,
109 },
110 (lhs, _) => lhs,
111 }
112 }
113
114 /// Final scalar — useful for tests and the planner's last fold.
115 pub fn finalize(self) -> Option<f64> {

Callers 2

aggregate_attrFunction · 0.45
group_by_dimFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected