Interface Grouper<KeyType>
-
- Type Parameters:
KeyType- type of the key that will be passed in
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Subinterfaces:
IntGrouper
- All Known Implementing Classes:
AbstractBufferHashGrouper,BufferArrayGrouper,BufferHashGrouper,ConcurrentGrouper,LimitedBufferHashGrouper,SpillingGrouper,StreamingMergeSortedGrouper
public interface Grouper<KeyType> extends Closeable
Groupers aggregate metrics from rows that they typically get from a ColumnSelectorFactory, under grouping keys that some outside driver is passing in. They can also iterate over the grouped rows after the aggregation is done. They work sort of like a map of KeyType to aggregated values, except they don't support random lookups. SeeVectorGrouperfor a vectorized version.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceGrouper.BufferComparatorstatic interfaceGrouper.Entry<T>static interfaceGrouper.KeySerde<T>Possibly-stateful object responsible for serde and comparison of keys.static interfaceGrouper.KeySerdeFactory<T>
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default AggregateResultaggregate(KeyType key)Aggregate the current row with the provided key.AggregateResultaggregate(KeyType key, int keyHash)Aggregate the current row with the provided key.voidclose()Close the grouper and release associated resources.default 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.voidreset()Reset the grouper to its initial state.
-
-
-
Method Detail
-
init
void init()
Initialize the grouper. This method needs to be called before callingaggregate(Object)andaggregate(Object, int).
-
isInitialized
boolean isInitialized()
Check this grouper is initialized or not.- Returns:
- true if the grouper is already initialized, otherwise false.
-
aggregate
AggregateResult aggregate(KeyType key, int keyHash)
Aggregate the current row with the provided key. Some implementations are thread-safe and some are not.- Parameters:
key- key objectkeyHash- result ofhashFunction()on the key- Returns:
- result that is ok if the row was aggregated, not ok if a resource limit was hit
-
aggregate
default AggregateResult aggregate(KeyType key)
Aggregate the current row with the provided key. Some implementations are thread-safe and some are not.- Parameters:
key- key- Returns:
- result that is ok if the row was aggregated, not ok if a resource limit was hit
-
reset
void reset()
Reset the grouper to its initial state.
-
hashFunction
default ToIntFunction<KeyType> hashFunction()
-
close
void close()
Close the grouper and release associated resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
iterator
CloseableIterator<Grouper.Entry<KeyType>> iterator(boolean sorted)
Iterate 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
close()(if you are done with the Grouper) orreset()(if you want to reuse it). Some implementations allow callingiterator(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
-
-