Interface Grouper<KeyType>

Type Parameters:
KeyType - type of the key that will be passed in
All Superinterfaces:
AutoCloseable, Closeable
All Known Subinterfaces:
IntGrouper
All Known Implementing Classes:
AbstractBufferHashGrouper, BufferArrayGrouper, BufferHashGrouper, ConcurrentGrouper, LimitedBufferHashGrouper, SpillingGrouper, StreamingMergeSortedGrouper

public interface Grouper<KeyType> extends Closeable
Groupers aggregate metrics from rows that they typically get from a ColumnSelectorFactory, under grouping keys that some outside driver is passing in. They can also iterate over the grouped rows after the aggregation is done. They work sort of like a map of KeyType to aggregated values, except they don't support random lookups. See VectorGrouper for a vectorized version.
  • Method Details

    • init

      void init()
      Initialize the grouper. This method needs to be called before calling aggregate(Object) and aggregate(Object, int).
    • isInitialized

      boolean isInitialized()
      Check this grouper is initialized or not.
      Returns:
      true if the grouper is already initialized, otherwise false.
    • aggregate

      AggregateResult aggregate(KeyType key, int keyHash)
      Aggregate the current row with the provided key. Some implementations are thread-safe and some are not.
      Parameters:
      key - key object
      keyHash - result of hashFunction() on the key
      Returns:
      result that is ok if the row was aggregated, not ok if a resource limit was hit
    • aggregate

      default AggregateResult aggregate(KeyType key)
      Aggregate the current row with the provided key. Some implementations are thread-safe and some are not.
      Parameters:
      key - key
      Returns:
      result that is ok if the row was aggregated, not ok if a resource limit was hit
    • reset

      void reset()
      Reset the grouper to its initial state.
    • hashFunction

      default ToIntFunction<KeyType> hashFunction()
    • close

      void close()
      Close the grouper and release associated resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • iterator

      CloseableIterator<Grouper.Entry<KeyType>> iterator(boolean sorted)
      Iterate through entries.

      Some implementations allow writes even after this method is called. After you are done with the iterator returned by this method, you should either call close() (if you are done with the Grouper) or reset() (if you want to reuse it). Some implementations allow calling iterator(boolean) again if you want another iterator. But, this method must not be called by multiple threads concurrently.

      If "sorted" is true then the iterator will return sorted results. It will use KeyType's natural ordering on deserialized objects, and will use the Grouper.KeySerde.bufferComparator() on serialized objects. Woe be unto you if these comparators are not equivalent.

      Callers must process and discard the returned Grouper.Entrys immediately because some implementations can reuse the key objects.

      Parameters:
      sorted - return sorted results
      Returns:
      entry iterator