Class HashAggAccumulator
java.lang.Object
dev.frostlake.functions.aggregate.HashAggAccumulator
- All Implemented Interfaces:
AggregateFunction.Accumulator,MultiArgumentAccumulator
public class HashAggAccumulator
extends Object
implements AggregateFunction.Accumulator, MultiArgumentAccumulator
Accumulator for
HashAgg. Every row's ARGUMENT TUPLE is hashed with the shared scalar
HashFn (FNV-1a over the UTF-8 encoding, NULL included as a stable sentinel) and the per-row
hashes are summed. Summation is commutative and associative, so the accumulated hash is independent
of the order in which rows arrive and of how partial accumulators are
merged, while each occurrence still contributes
(duplicates are not cancelled out as they would be with XOR). An empty group yields 0, not NULL
(live-verified: HASH_AGG over zero rows is 0, while a group of NULLs is not — a NULL row contributes
like any other).
THE ROW HASH IS FOLDED ONCE MORE before it is added. Without that, a group of ONE row would
necessarily equal the scalar HASH of that row — and live's does not, in the one-argument and
the multi-argument form alike, so the two functions are not the same function seen through a group of
one. The fold is an FNV-1a pass over the row hash's own eight bytes: a bijection on 64 bits, so every
relation the sum gives — order independence, duplicates counting, a scale being invisible, a VARIANT
JSON null staying apart from SQL NULL — survives it untouched.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulate(Object value) Folds one row's argument value into the running state.voidaccumulate(List<Object> argumentValues) The multi-argument form: live folds EVERY argument of each row, soHASH_AGG(a, b)andHASH_AGG(a, b, c)give different answers over the same rows.The aggregate's result over everything accumulated so far.voidFolds another accumulator's state into this one, combining two partial aggregations of the same group.voidreset()Clears the state back to the empty-group starting point so the accumulator can be reused.
-
Constructor Details
-
HashAggAccumulator
public HashAggAccumulator()
-
-
Method Details
-
accumulate
Description copied from interface:AggregateFunction.AccumulatorFolds one row's argument value into the running state.- Specified by:
accumulatein interfaceAggregateFunction.Accumulator- Parameters:
value- the aggregate argument's value for one row; SQL NULL arrives asnull
-
accumulate
The multi-argument form: live folds EVERY argument of each row, soHASH_AGG(a, b)andHASH_AGG(a, b, c)give different answers over the same rows. Reading only the first argument silently dropped the rest.- Specified by:
accumulatein interfaceMultiArgumentAccumulator- Parameters:
argumentValues- one row's values, one per declared argument, in the order written
-
getResult
Description copied from interface:AggregateFunction.AccumulatorThe aggregate's result over everything accumulated so far.- Specified by:
getResultin interfaceAggregateFunction.Accumulator- Returns:
- the group's result, or
nullwhere the aggregate defines an empty group as NULL
-
reset
public void reset()Description copied from interface:AggregateFunction.AccumulatorClears the state back to the empty-group starting point so the accumulator can be reused.- Specified by:
resetin interfaceAggregateFunction.Accumulator
-
merge
Description copied from interface:AggregateFunction.AccumulatorFolds another accumulator's state into this one, combining two partial aggregations of the same group.- Specified by:
mergein interfaceAggregateFunction.Accumulator- Parameters:
other- a partial state of the same aggregate implementation
-