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>
-
-
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 inherited from class org.apache.druid.query.groupby.epinephelinae.AbstractBufferHashGrouper
aggregators, baseAggregatorOffset, bucketSize, bufferGrouperMaxSize, bufferSupplier, HASH_SIZE, hashTable, hashTableBuffer, initialBuckets, keySerde, keySize, log, maxLoadFactor
-
-
Constructor Summary
Constructors Constructor Description BufferHashGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerde<KeyType> keySerde, AggregatorAdapters aggregators, int bufferGrouperMaxSize, float maxLoadFactor, int initialBuckets, boolean useDefaultSorting)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAggregateHook(int bucketOffset)Called after a row is aggregated.booleancanSkipAggregate(int bucketOffset)Called to check if it's possible to skip aggregation for a row.ToIntFunction<KeyType>hashFunction()voidinit()Initialize the grouper.booleanisInitialized()Check this grouper is initialized or not.CloseableIterator<Grouper.Entry<KeyType>>iterator(boolean sorted)Iterate through entries.voidnewBucketHook(int bucketOffset)Called when a new bucket is used for an entry in the hash table.voidreset()Reset the grouper to its initial state.-
Methods inherited from class org.apache.druid.query.groupby.epinephelinae.AbstractBufferHashGrouper
aggregate, close, getBuckets, getGrowthCount, getMaxSize, getSize, populateBucketEntryForOffset
-
-
-
-
Constructor Detail
-
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 Detail
-
init
public void init()
Description copied from interface:GrouperInitialize the grouper. This method needs to be called before callingGrouper.aggregate(Object)andGrouper.aggregate(Object, int).
-
isInitialized
public boolean isInitialized()
Description copied from interface:GrouperCheck this grouper is initialized or not.- Returns:
- true if the grouper is already initialized, otherwise false.
-
hashFunction
public ToIntFunction<KeyType> hashFunction()
-
newBucketHook
public void newBucketHook(int bucketOffset)
Description copied from class:AbstractBufferHashGrouperCalled 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:
newBucketHookin classAbstractBufferHashGrouper<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:AbstractBufferHashGrouperCalled to check if it's possible to skip aggregation for a row.- Specified by:
canSkipAggregatein classAbstractBufferHashGrouper<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:AbstractBufferHashGrouperCalled 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:
afterAggregateHookin classAbstractBufferHashGrouper<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:GrouperReset the grouper to its initial state.
-
iterator
public CloseableIterator<Grouper.Entry<KeyType>> iterator(boolean sorted)
Description copied from interface:GrouperIterate 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) orGrouper.reset()(if you want to reuse it). Some implementations allow callingGrouper.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
-
-