Class ConcurrentGrouper<KeyType>
- All Implemented Interfaces:
Closeable,AutoCloseable,Grouper<KeyType>
SpillingGrouper instances. Thread-safe.
The passed-in buffer is cut up into concurrencyHint slices, and each slice is passed to a different underlying grouper. Access to each slice is separately synchronized. As long as the result set fits in memory, keys are partitioned between buffers based on their hash, and multiple threads can write into the same buffer. When it becomes clear that the result set does not fit in memory, the table switches to a mode where each thread gets its own buffer and its own spill files on disk.
-
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> -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentGrouper(GroupByQueryConfig groupByQueryConfig, com.google.common.base.Supplier<ByteBuffer> bufferSupplier, ReferenceCountingResourceHolder<ByteBuffer> combineBufferHolder, Grouper.KeySerdeFactory<KeyType> keySerdeFactory, Grouper.KeySerdeFactory<KeyType> combineKeySerdeFactory, ColumnSelectorFactory columnSelectorFactory, AggregatorFactory[] aggregatorFactories, LimitedTemporaryStorage temporaryStorage, com.fasterxml.jackson.databind.ObjectMapper spillMapper, int concurrencyHint, DefaultLimitSpec limitSpec, boolean sortHasNonGroupingFields, com.google.common.util.concurrent.ListeningExecutorService executor, int priority, boolean hasQueryTimeout, long queryTimeoutAt, GroupByStatsProvider.PerQueryStats perQueryStats) -
Method Summary
Modifier and TypeMethodDescriptionAggregate the current row with the provided key.voidclose()Close the grouper and release associated resources.voidinit()Initialize the grouper.booleanCheck this grouper is initialized or not.iterator(boolean sorted) Iterate through entries.voidreset()Reset the grouper to its initial state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.query.groupby.epinephelinae.Grouper
aggregate, hashFunction
-
Constructor Details
-
ConcurrentGrouper
public ConcurrentGrouper(GroupByQueryConfig groupByQueryConfig, com.google.common.base.Supplier<ByteBuffer> bufferSupplier, @Nullable ReferenceCountingResourceHolder<ByteBuffer> combineBufferHolder, Grouper.KeySerdeFactory<KeyType> keySerdeFactory, Grouper.KeySerdeFactory<KeyType> combineKeySerdeFactory, ColumnSelectorFactory columnSelectorFactory, AggregatorFactory[] aggregatorFactories, LimitedTemporaryStorage temporaryStorage, com.fasterxml.jackson.databind.ObjectMapper spillMapper, int concurrencyHint, DefaultLimitSpec limitSpec, boolean sortHasNonGroupingFields, com.google.common.util.concurrent.ListeningExecutorService executor, int priority, boolean hasQueryTimeout, long queryTimeoutAt, GroupByStatsProvider.PerQueryStats perQueryStats)
-
-
Method Details
-
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.- Specified by:
isInitializedin interfaceGrouper<KeyType>- Returns:
- true if the grouper is already initialized, otherwise false.
-
aggregate
Description copied from interface:GrouperAggregate the current row with the provided key. Some implementations are thread-safe and some are not.- Specified by:
aggregatein 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
-
reset
public void reset()Description copied from interface:GrouperReset the grouper to its initial state. -
iterator
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. -
close
public void close()Description copied from interface:GrouperClose the grouper and release associated resources.
-