Class AvgAccumulator
java.lang.Object
dev.frostlake.functions.aggregate.AvgAccumulator
- All Implemented Interfaces:
ApproximateAwareAccumulator,AggregateFunction.Accumulator
public class AvgAccumulator
extends Object
implements AggregateFunction.Accumulator, ApproximateAwareAccumulator
Accumulator for
Avg, delegating the numeric result to AggregateNumerics.avg(Iterable) so
every AVG code path shares the same live-verified Snowflake typing: fixed-point inputs (Long/Integer/
BigDecimal) yield a BigDecimal with scale = (max input scale) + 6 rounded HALF_UP and trailing zeros kept
(AVG of 90 and 95 is exactly 92.500000), while any Double/Float/VARIANT input keeps the double average.
NULL inputs are ignored; no non-null input yields NULL.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulate(Object value) Folds one row's argument value into the running state.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.voidsetApproximateArgument(boolean approximate) The argument's DECLARED type, which the values alone cannot say: a FLOAT column is stored exactly here, so only this flag keeps its average on the double path.
-
Constructor Details
-
AvgAccumulator
public AvgAccumulator()
-
-
Method Details
-
setApproximateArgument
public void setApproximateArgument(boolean approximate) The argument's DECLARED type, which the values alone cannot say: a FLOAT column is stored exactly here, so only this flag keeps its average on the double path. Without it live's 2.333333333 came back 2.333333, padded to the scale an exact input would have earned.- Specified by:
setApproximateArgumentin interfaceApproximateAwareAccumulator- Parameters:
approximate- whether the aggregated expression is declared FLOAT / DOUBLE / REAL
-
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
-