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>
ThisTopNAlgorithmis highly specialized for processing aggregates on string columns that areColumnCapabilities.isDictionaryEncoded()andColumnCapabilities.areDictionaryValuesUnique(). This algorithm is built around using a directByteBufferfrom 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, seecomputeSpecializedScanAndAggregateImplementations(),Generic1AggPooledTopNScannerandGeneric1AggPooledTopNScannerPrototype,Generic2AggPooledTopNScannerandGeneric2AggPooledTopNScannerPrototype,CalledFromHotLoop,HotLoopCallee,RuntimeShapeInspectorfor more details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPooledTopNAlgorithm.PooledTopNParams-
Nested 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
cursorInspector
-
Fields inherited from interface org.apache.druid.query.topn.TopNAlgorithm
EMPTY_ARRAY, INIT_POSITION_VALUE, SKIP_POSITION_VALUE
-
-
Constructor Summary
Constructors Constructor Description PooledTopNAlgorithm(TopNQuery query, TopNCursorInspector cursorInspector, NonBlockingPool<ByteBuffer> bufferPool)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup(PooledTopNAlgorithm.PooledTopNParams params)protected 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[]makeDimValAggregateStore(PooledTopNAlgorithm.PooledTopNParams params)protected int[]makeDimValSelector(PooledTopNAlgorithm.PooledTopNParams params, int numProcessed, int numToProcess)PooledTopNAlgorithm.PooledTopNParamsmakeInitParams(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 Detail
-
PooledTopNAlgorithm
public PooledTopNAlgorithm(TopNQuery query, TopNCursorInspector cursorInspector, NonBlockingPool<ByteBuffer> bufferPool)
-
-
Method Detail
-
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
protected BufferAggregator[] makeDimValAggregateStore(PooledTopNAlgorithm.PooledTopNParams params)
- 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
protected void resetAggregators(BufferAggregator[] bufferAggregators)
- Specified by:
resetAggregatorsin classBaseTopNAlgorithm<int[],BufferAggregator[],PooledTopNAlgorithm.PooledTopNParams>
-
cleanup
public void cleanup(PooledTopNAlgorithm.PooledTopNParams params)
-
-