Class BufferHashGrouper<KeyType>

java.lang.Object
org.apache.druid.query.groupby.epinephelinae.AbstractBufferHashGrouper<KeyType>
org.apache.druid.query.groupby.epinephelinae.BufferHashGrouper<KeyType>
All Implemented Interfaces:
Closeable, AutoCloseable, Grouper<KeyType>

public class BufferHashGrouper<KeyType> extends AbstractBufferHashGrouper<KeyType>
  • Constructor Details

    • BufferHashGrouper

      public BufferHashGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerde<KeyType> keySerde, AggregatorAdapters aggregators, int bufferGrouperMaxSize, float maxLoadFactor, int initialBuckets, boolean useDefaultSorting)
  • Method Details

    • init

      public void init()
      Description copied from interface: Grouper
      Initialize the grouper. This method needs to be called before calling Grouper.aggregate(Object) and Grouper.aggregate(Object, int).
    • isInitialized

      public boolean isInitialized()
      Description copied from interface: Grouper
      Check this grouper is initialized or not.
      Returns:
      true if the grouper is already initialized, otherwise false.
    • newBucketHook

      public void newBucketHook(int bucketOffset)
      Description copied from class: AbstractBufferHashGrouper
      Called when a new bucket is used for an entry in the hash table. An implementing BufferHashGrouper class can use this to update its own state, e.g. tracking bucket offsets in a structure outside of the hash table.
      Specified by:
      newBucketHook in class AbstractBufferHashGrouper<KeyType>
      Parameters:
      bucketOffset - offset of the new bucket, within the buffer returned by hashTable.getTableBuffer()
    • canSkipAggregate

      public boolean canSkipAggregate(int bucketOffset)
      Description copied from class: AbstractBufferHashGrouper
      Called to check if it's possible to skip aggregation for a row.
      Specified by:
      canSkipAggregate in class AbstractBufferHashGrouper<KeyType>
      Parameters:
      bucketOffset - Offset of the bucket containing this row's entry in the hash table, within the buffer returned by hashTable.getTableBuffer()
      Returns:
      true if aggregation can be skipped, false otherwise.
    • afterAggregateHook

      public void afterAggregateHook(int bucketOffset)
      Description copied from class: AbstractBufferHashGrouper
      Called after a row is aggregated. An implementing BufferHashGrouper class can use this to update its own state, e.g. reading the new aggregated values for the row's key and acting on that information.
      Specified by:
      afterAggregateHook in class AbstractBufferHashGrouper<KeyType>
      Parameters:
      bucketOffset - Offset of the bucket containing the row that was aggregated, within the buffer returned by hashTable.getTableBuffer()
    • reset

      public void reset()
      Description copied from interface: Grouper
      Reset the grouper to its initial state.
    • iterator

      public CloseableIterator<Grouper.Entry<KeyType>> iterator(boolean sorted)
      Description copied from interface: Grouper
      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 Grouper.close() (if you are done with the Grouper) or Grouper.reset() (if you want to reuse it). Some implementations allow calling Grouper.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