pub enum Agg {
Min,
Max,
Sum,
}Expand description
Which aggregate a Op::GroupBy maintains.
Three rather than four: count is the join’s own tally (Matching::Count) because a count
needs nothing of the row at all.
Every one of them is a function of which numbers its group’s rows project to and of nothing
else — not of the order they arrived in, not of the order the collection holds them in. That is
what makes a maintained answer and a recomputed one the same value rather than nearly the same
one, and it is why sum waited for a spelling rather than for an implementation
(docs/99 §99.9 item 6). It is a
statement about the answer rather than about the state: what an operator has to keep in order
to give it differs per aggregate, and for a sum it is not a multiset at all.
Variants§
Min
The smallest projection in the group, by crate::Value’s own total order — which is what
list_min compares, so the maintained answer and the recomputed one are the same function
of the same set.
Max
The largest, and it costs what Agg::Min costs.
Sum
The total of the group’s projections — list_sum, whose answer is Int and whose empty
group is 0 rather than None, which is what Matching::Total exists to say.
This one keeps no multiset. A running total moves by +n and -n as rows arrive and
leave, so the group’s distinct values are not a thing it has to know, and the probe is
O(1) rather than the O(distinct) a sum derived from Agg::Min’s tree would cost. The
accumulator is wider than the answer for list_sum’s reason: the sum is exact and the
failure is a property of the total, not of the way there.