Class RegrAccumulator
java.lang.Object
dev.frostlake.functions.aggregate.RegrAccumulator
- All Implemented Interfaces:
AggregateFunction.Accumulator
Shared accumulator for the REGR_* linear-regression family. All nine functions are derived from the same
running sums over the non-null (y, x) pairs — note Snowflake's argument order
REGR_xxx(y, x), with
the dependent variable y first and the independent variable x second. getResult() returns the
member selected by RegrKind.
With n pairs and centered sums Sxx = Σx² − (Σx)²/n, Syy, Sxy:
COUNT = n; AVGX = Σx/n; AVGY = Σy/n; SXX = Sxx; SYY = Syy; SXY = Sxy; SLOPE = Sxy/Sxx;
INTERCEPT = AVGY − SLOPE·AVGX; R2 = NULL if Sxx=0, else 1 if Syy=0, else Sxy²/(Sxx·Syy) (= CORR²).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulate(double y, double x) Accumulate one non-null pair.voidaccumulate(Object value) Folds one row's argument value into the running state.The aggregate's result over everything accumulated so far.kind()The member this accumulator computes, which decides which side of a pair is read at all.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
-
RegrAccumulator
-
-
Method Details
-
kind
The member this accumulator computes, which decides which side of a pair is read at all. -
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
public void accumulate(double y, double x) Accumulate one non-null pair. Snowflake order:yis the dependent (first) arg,xthe second. -
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
-