Class AbstractBufferHashGrouper<KeyType>

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

public abstract class AbstractBufferHashGrouper<KeyType> extends Object implements Grouper<KeyType>
  • Field Details

    • HASH_SIZE

      protected static final int HASH_SIZE
      See Also:
    • log

      protected static final Logger log
    • bufferSupplier

      protected final com.google.common.base.Supplier<ByteBuffer> bufferSupplier
    • keySerde

      protected final Grouper.KeySerde<KeyType> keySerde
    • keySize

      protected final int keySize
    • aggregators

      protected final AggregatorAdapters aggregators
    • baseAggregatorOffset

      protected final int baseAggregatorOffset
    • bufferGrouperMaxSize

      protected final int bufferGrouperMaxSize
    • maxLoadFactor

      protected float maxLoadFactor
    • initialBuckets

      protected int initialBuckets
    • bucketSize

      protected int bucketSize
    • hashTable

      protected ByteBufferHashTable hashTable
    • hashTableBuffer

      protected ByteBuffer hashTableBuffer
  • Constructor Details

  • Method Details

    • newBucketHook

      public abstract void newBucketHook(int bucketOffset)
      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.
      Parameters:
      bucketOffset - offset of the new bucket, within the buffer returned by hashTable.getTableBuffer()
    • canSkipAggregate

      public abstract boolean canSkipAggregate(int bucketOffset)
      Called to check if it's possible to skip aggregation for a row.
      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 abstract void afterAggregateHook(int bucketOffset)
      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.
      Parameters:
      bucketOffset - Offset of the bucket containing the row that was aggregated, within the buffer returned by hashTable.getTableBuffer()
    • getGrowthCount

      public int getGrowthCount()
    • getSize

      public int getSize()
    • getBuckets

      public int getBuckets()
    • getMaxSize

      public int getMaxSize()
    • aggregate

      public AggregateResult aggregate(KeyType key, int keyHash)
      Description copied from interface: Grouper
      Aggregate the current row with the provided key. Some implementations are thread-safe and some are not.
      Specified by:
      aggregate in interface Grouper<KeyType>
      Parameters:
      key - key object
      keyHash - result of Grouper.hashFunction() on the key
      Returns:
      result that is ok if the row was aggregated, not ok if a resource limit was hit
    • close

      public void close()
      Description copied from interface: Grouper
      Close the grouper and release associated resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Grouper<KeyType>
    • getMaxMergeBufferUsedBytes

      public long getMaxMergeBufferUsedBytes()
      Retrieves the size of the merge buffers used for this groupby query. This value is retrieved when SpillingGrouper.close() is called.

      This method is implemented to return the highest memory value used, this is helpful especially in reporting the highest number of bytes used throughout the entire query lifecycle.
    • populateBucketEntryForOffset

      protected Grouper.Entry<KeyType> populateBucketEntryForOffset(ReusableEntry<KeyType> reusableEntry, int bucketOffset)
      Populate a ReusableEntry with values from a particular bucket.