Class HllAccumulator
java.lang.Object
dev.frostlake.functions.aggregate.HllAccumulator
- All Implemented Interfaces:
AggregateFunction.Accumulator,MultiArgumentAccumulator
public class HllAccumulator
extends Object
implements AggregateFunction.Accumulator, MultiArgumentAccumulator
HyperLogLog sketch for APPROX_COUNT_DISTINCT (Flajolet et al.), with linear counting in the
small-cardinality range. Replaces the previous approach — an exact
HashSet of 32-bit
String.hashCode() values — which could UNDERCOUNT whenever two distinct values collided on
hashCode (e.g. "Aa" and "BB"). Each value's string form is hashed to 64 bits, so distinct values are
(with overwhelming probability) counted separately. With p = 14 registers the standard error
is ~0.8%, and linear counting keeps cardinalities up to ~40k (near-)exact.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulate(Object value) Folds one row's argument value into the running state.voidaccumulate(List<Object> argumentValues) A multi-argument call counts distinct TUPLES, and a tuple with any NULL member is skipped whole — live counts (1.5, 7) once over {(1.5, 7), (1.5, NULL), (NULL, 7), (NULL, NULL), (1.5, 7)}.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
-
HllAccumulator
public HllAccumulator()
-
-
Method Details
-
accumulate
A multi-argument call counts distinct TUPLES, and a tuple with any NULL member is skipped whole — live counts (1.5, 7) once over {(1.5, 7), (1.5, NULL), (NULL, 7), (NULL, NULL), (1.5, 7)}.- Specified by:
accumulatein interfaceMultiArgumentAccumulator
-
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
-
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
-