Class HashAggAccumulator

java.lang.Object
dev.frostlake.functions.aggregate.HashAggAccumulator
All Implemented Interfaces:
AggregateFunction.Accumulator, MultiArgumentAccumulator

public class HashAggAccumulator extends Object implements AggregateFunction.Accumulator, MultiArgumentAccumulator
Accumulator for HashAgg. Every row's ARGUMENT TUPLE is hashed with the shared scalar HashFn (FNV-1a over the UTF-8 encoding, NULL included as a stable sentinel) and the per-row hashes are summed. Summation is commutative and associative, so the accumulated hash is independent of the order in which rows arrive and of how partial accumulators are merged, while each occurrence still contributes (duplicates are not cancelled out as they would be with XOR). An empty group yields 0, not NULL (live-verified: HASH_AGG over zero rows is 0, while a group of NULLs is not — a NULL row contributes like any other).

THE ROW HASH IS FOLDED ONCE MORE before it is added. Without that, a group of ONE row would necessarily equal the scalar HASH of that row — and live's does not, in the one-argument and the multi-argument form alike, so the two functions are not the same function seen through a group of one. The fold is an FNV-1a pass over the row hash's own eight bytes: a bijection on 64 bits, so every relation the sum gives — order independence, duplicates counting, a scale being invisible, a VARIANT JSON null staying apart from SQL NULL — survives it untouched.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Folds one row's argument value into the running state.
    void
    accumulate(List<Object> argumentValues)
    The multi-argument form: live folds EVERY argument of each row, so HASH_AGG(a, b) and HASH_AGG(a, b, c) give different answers over the same rows.
    The aggregate's result over everything accumulated so far.
    void
    Folds another accumulator's state into this one, combining two partial aggregations of the same group.
    void
    Clears the state back to the empty-group starting point so the accumulator can be reused.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HashAggAccumulator

      public HashAggAccumulator()
  • Method Details