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>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.druid.query.groupby.epinephelinae.Grouper
Grouper.BufferComparator, Grouper.Entry<T>, Grouper.KeySerde<T>, Grouper.KeySerdeFactory<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected AggregatorAdapters
aggregators
protected int
baseAggregatorOffset
protected int
bucketSize
protected int
bufferGrouperMaxSize
protected com.google.common.base.Supplier<ByteBuffer>
bufferSupplier
protected static int
HASH_SIZE
protected ByteBufferHashTable
hashTable
protected ByteBuffer
hashTableBuffer
protected int
initialBuckets
protected Grouper.KeySerde<KeyType>
keySerde
protected int
keySize
protected static Logger
log
protected float
maxLoadFactor
-
Constructor Summary
Constructors Constructor Description AbstractBufferHashGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerde<KeyType> keySerde, AggregatorAdapters aggregators, int baseAggregatorOffset, int bufferGrouperMaxSize)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
afterAggregateHook(int bucketOffset)
Called after a row is aggregated.AggregateResult
aggregate(KeyType key, int keyHash)
Aggregate the current row with the provided key.abstract boolean
canSkipAggregate(int bucketOffset)
Called to check if it's possible to skip aggregation for a row.void
close()
Close the grouper and release associated resources.int
getBuckets()
int
getGrowthCount()
int
getMaxSize()
int
getSize()
abstract void
newBucketHook(int bucketOffset)
Called when a new bucket is used for an entry in the hash table.protected Grouper.Entry<KeyType>
populateBucketEntryForOffset(ReusableEntry<KeyType> reusableEntry, int bucketOffset)
Populate aReusableEntry
with values from a particular bucket.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.query.groupby.epinephelinae.Grouper
aggregate, hashFunction, init, isInitialized, iterator, reset
-
-
-
-
Field Detail
-
HASH_SIZE
protected static final int HASH_SIZE
- See Also:
- Constant Field Values
-
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 Detail
-
AbstractBufferHashGrouper
public AbstractBufferHashGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerde<KeyType> keySerde, AggregatorAdapters aggregators, int baseAggregatorOffset, int bufferGrouperMaxSize)
-
-
Method Detail
-
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 interfaceGrouper<KeyType>
- Parameters:
key
- key objectkeyHash
- result ofGrouper.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.
-
populateBucketEntryForOffset
protected Grouper.Entry<KeyType> populateBucketEntryForOffset(ReusableEntry<KeyType> reusableEntry, int bucketOffset)
Populate aReusableEntry
with values from a particular bucket.
-
-