Class MaxByMinByAccumulator

java.lang.Object
dev.frostlake.functions.aggregate.MaxByMinByAccumulator
All Implemented Interfaces:
AggregateFunction.Accumulator

public class MaxByMinByAccumulator extends Object implements 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 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

      public void accumulate(Object value)
      Description copied from interface: AggregateFunction.Accumulator
      Folds one row's argument value into the running state.
      Specified by:
      accumulate in interface AggregateFunction.Accumulator
      Parameters:
      value - the aggregate argument's value for one row; SQL NULL arrives as null
    • accumulate

      public void accumulate(Object value, Object key)
      Offer one (value, key) pair. A NULL key is ignored; only a key that strictly beats the current best wins.
    • getResult

      public Object getResult()
      Description copied from interface: AggregateFunction.Accumulator
      The aggregate's result over everything accumulated so far.
      Specified by:
      getResult in interface AggregateFunction.Accumulator
      Returns:
      the group's result, or null where the aggregate defines an empty group as NULL
    • reset

      public void reset()
      Description copied from interface: AggregateFunction.Accumulator
      Clears the state back to the empty-group starting point so the accumulator can be reused.
      Specified by:
      reset in interface AggregateFunction.Accumulator
    • merge

      public void merge(AggregateFunction.Accumulator other)
      Description copied from interface: AggregateFunction.Accumulator
      Folds another accumulator's state into this one, combining two partial aggregations of the same group.
      Specified by:
      merge in interface AggregateFunction.Accumulator
      Parameters:
      other - a partial state of the same aggregate implementation