Class SpillingGrouper<KeyType>
- All Implemented Interfaces:
Closeable,AutoCloseable,Grouper<KeyType>
BufferHashGrouper. Not thread-safe.
When the underlying grouper is full, its contents are sorted and written to temporary files using "spillMapper".-
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
ConstructorsConstructorDescriptionSpillingGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerdeFactory<KeyType> keySerdeFactory, ColumnSelectorFactory columnSelectorFactory, AggregatorFactory[] aggregatorFactories, int bufferGrouperMaxSize, float bufferGrouperMaxLoadFactor, int bufferGrouperInitialBuckets, LimitedTemporaryStorage temporaryStorage, com.fasterxml.jackson.databind.ObjectMapper spillMapper, boolean spillingAllowed, DefaultLimitSpec limitSpec, boolean sortHasNonGroupingFields, int mergeBufferSize, 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.booleaniterator(boolean sorted) Iterate through entries.Returns a dictionary of string keys added to this grouper.voidreset()Reset the grouper to its initial state.voidsetSpillingAllowed(boolean spillingAllowed) 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
-
SpillingGrouper
public SpillingGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerdeFactory<KeyType> keySerdeFactory, ColumnSelectorFactory columnSelectorFactory, AggregatorFactory[] aggregatorFactories, int bufferGrouperMaxSize, float bufferGrouperMaxLoadFactor, int bufferGrouperInitialBuckets, LimitedTemporaryStorage temporaryStorage, com.fasterxml.jackson.databind.ObjectMapper spillMapper, boolean spillingAllowed, DefaultLimitSpec limitSpec, boolean sortHasNonGroupingFields, int mergeBufferSize, 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. -
close
public void close()Description copied from interface:GrouperClose the grouper and release associated resources. -
mergeAndGetDictionary
Returns a dictionary of string keys added to this grouper. Note that the dictionary of keySerde is spilled on local storage whenever the inner grouper is spilled. If there are spilled dictionaries, this method loads them from disk and returns a merged dictionary.- Returns:
- a dictionary which is a list of unique strings
-
isSpillingAllowed
public boolean isSpillingAllowed() -
setSpillingAllowed
public void setSpillingAllowed(boolean spillingAllowed) -
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.
-