Package org.apache.druid.query.topn
Class PooledTopNAlgorithm
java.lang.Object
org.apache.druid.query.topn.BaseTopNAlgorithm<int[],BufferAggregator[],PooledTopNAlgorithm.PooledTopNParams>
org.apache.druid.query.topn.PooledTopNAlgorithm
- All Implemented Interfaces:
TopNAlgorithm<int[],PooledTopNAlgorithm.PooledTopNParams>
public class PooledTopNAlgorithm
extends BaseTopNAlgorithm<int[],BufferAggregator[],PooledTopNAlgorithm.PooledTopNParams>
This
TopNAlgorithm is highly specialized for processing aggregates on string columns that are
ColumnCapabilities.isDictionaryEncoded() and ColumnCapabilities.areDictionaryValuesUnique(). This
algorithm is built around using a direct ByteBuffer from the 'processing pool' of intermediary results
buffers, to aggregate using the dictionary id directly as the key, to defer looking up the value until is necessary.
At runtime, this implementation is specialized with wizardry to optimize for processing common top-n query shapes,
see computeSpecializedScanAndAggregateImplementations(),
Generic1AggPooledTopNScanner and Generic1AggPooledTopNScannerPrototype,
Generic2AggPooledTopNScanner and Generic2AggPooledTopNScannerPrototype,
CalledFromHotLoop,
HotLoopCallee,
RuntimeShapeInspector for more details.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.druid.query.topn.BaseTopNAlgorithm
BaseTopNAlgorithm.AggregatorArrayProvider, BaseTopNAlgorithm.BaseArrayProvider<T> -
Field Summary
Fields inherited from class org.apache.druid.query.topn.BaseTopNAlgorithm
cursorInspectorFields inherited from interface org.apache.druid.query.topn.TopNAlgorithm
EMPTY_ARRAY, INIT_POSITION_VALUE, SKIP_POSITION_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionPooledTopNAlgorithm(TopNQuery query, TopNCursorInspector cursorInspector, NonBlockingPool<ByteBuffer> bufferPool) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected intcomputeNewLength(int[] dimValSelector, int numProcessed, int numToProcess) Skip invalid value, calculate length to have enough valid value to process or hit the end.protected BufferAggregator[]protected int[]makeDimValSelector(PooledTopNAlgorithm.PooledTopNParams params, int numProcessed, int numToProcess) makeInitParams(ColumnSelectorPlus selectorPlus, Cursor cursor, CursorGranularizer granularizer) protected voidresetAggregators(BufferAggregator[] bufferAggregators) protected longscanAndAggregate(PooledTopNAlgorithm.PooledTopNParams params, int[] positions, BufferAggregator[] theAggregators) Returns the number of processed rows (i.protected int[]updateDimValSelector(int[] dimValSelector, int numProcessed, int numToProcess) protected voidupdateResults(PooledTopNAlgorithm.PooledTopNParams params, int[] positions, BufferAggregator[] theAggregators, TopNResultBuilder resultBuilder) Methods inherited from class org.apache.druid.query.topn.BaseTopNAlgorithm
makeAggregators, makeBufferAggregators, makeResultBuilder, run
-
Constructor Details
-
PooledTopNAlgorithm
public PooledTopNAlgorithm(TopNQuery query, TopNCursorInspector cursorInspector, NonBlockingPool<ByteBuffer> bufferPool)
-
-
Method Details
-
makeInitParams
public PooledTopNAlgorithm.PooledTopNParams makeInitParams(ColumnSelectorPlus selectorPlus, Cursor cursor, CursorGranularizer granularizer) -
makeDimValSelector
protected int[] makeDimValSelector(PooledTopNAlgorithm.PooledTopNParams params, int numProcessed, int numToProcess) - Specified by:
makeDimValSelectorin classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
computeNewLength
protected int computeNewLength(int[] dimValSelector, int numProcessed, int numToProcess) Description copied from class:BaseTopNAlgorithmSkip invalid value, calculate length to have enough valid value to process or hit the end.- Overrides:
computeNewLengthin classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams> - Parameters:
dimValSelector- the dim value selector which record value is valid or invalid.numProcessed- the start position to processnumToProcess- the number of valid value to process- Returns:
- the length between which have enough valid value to process or hit the end.
-
updateDimValSelector
protected int[] updateDimValSelector(int[] dimValSelector, int numProcessed, int numToProcess) - Specified by:
updateDimValSelectorin classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
makeDimValAggregateStore
- Specified by:
makeDimValAggregateStorein classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
scanAndAggregate
protected long scanAndAggregate(PooledTopNAlgorithm.PooledTopNParams params, int[] positions, BufferAggregator[] theAggregators) Description copied from class:BaseTopNAlgorithmReturns the number of processed rows (i. e. after postFilters are applied inside the cursor being processed).- Specified by:
scanAndAggregatein classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
updateResults
protected void updateResults(PooledTopNAlgorithm.PooledTopNParams params, int[] positions, BufferAggregator[] theAggregators, TopNResultBuilder resultBuilder) - Specified by:
updateResultsin classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
resetAggregators
- Specified by:
resetAggregatorsin classBaseTopNAlgorithm<int[],BufferAggregator[], PooledTopNAlgorithm.PooledTopNParams>
-
cleanup
-