Class MaxByMinByAccumulator
java.lang.Object
dev.frostlake.functions.aggregate.MaxByMinByAccumulator
- All Implemented Interfaces:
AggregateFunction.Accumulator
Shared accumulator for
MaxBy and MinBy. Unlike the numeric two-argument aggregates (CORR,
COVAR, REGR) it keeps RAW objects: the returned value may be any type and the sort key may
be any Comparable. Rows whose key is NULL are ignored. The wantMax flag selects whether the
maximum or minimum key wins; ties are resolved in favour of the FIRST-encountered row (live-verified:
MAX_BY over ('first', 10), ('second', 10) is 'first'), so only a strictly better key replaces the best.
The executor drives this via the two-argument accumulate(Object, Object) overload with the raw
column values; the single-argument accumulate(Object) inherited from the interface is unused.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulate(Object value) Folds one row's argument value into the running state.voidaccumulate(Object value, Object key) Offer one(value, key)pair.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.voidsetLimit(int limit, boolean distinct) Switch to the bounded (array-returning) form with the given cap; DISTINCT dedups values.
-
Constructor Details
-
MaxByMinByAccumulator
public MaxByMinByAccumulator(boolean wantMax)
-
-
Method Details
-
setLimit
public void setLimit(int limit, boolean distinct) Switch to the bounded (array-returning) form with the given cap; DISTINCT dedups values. -
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
Offer one(value, key)pair. A NULL key is ignored; only a key that strictly beats the current best wins. -
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
-