Interface TopNColumnAggregatesProcessor<ValueSelectorType>

All Superinterfaces:
ColumnSelectorStrategy
All Known Implementing Classes:
DoubleTopNColumnAggregatesProcessor, FloatTopNColumnAggregatesProcessor, LongTopNColumnAggregatesProcessor, NullableNumericTopNColumnAggregatesProcessor, StringTopNColumnAggregatesProcessor

public interface TopNColumnAggregatesProcessor<ValueSelectorType> extends ColumnSelectorStrategy
This ColumnSelectorStrategy is used by all TopNAlgorithm to provide selector value cardinality to TopNParams (perhaps unecessarily, but that is another matter), but is primarily used by HeapBasedTopNAlgorithm to serve as its value aggregates store. Given a query, column value selector, and cursor to process, the aggregates store is populated by calling scanAndAggregate(org.apache.druid.query.topn.TopNQuery, ValueSelectorType, org.apache.druid.segment.Cursor, org.apache.druid.query.CursorGranularizer, org.apache.druid.query.aggregation.Aggregator[][]) and can be applied to TopNResultBuilder through updateResults(org.apache.druid.query.topn.TopNResultBuilder).
  • Method Details

    • getCardinality

      int getCardinality(ValueSelectorType selector)
      Get value cardinality of underlying ColumnValueSelector
    • getRowSelector

      @Nullable Aggregator[][] getRowSelector(TopNQuery query, TopNParams params, TopNCursorInspector cursorInspector)
      Used by HeapBasedTopNAlgorithm. Create an Aggregator[][] using BaseTopNAlgorithm.AggregatorArrayProvider and the given parameters. As the Aggregator[][] is used as an integer-based lookup, this method is only applicable for dimension types that use integer row values, e.g. string columns where the value cardinality is known. A dimension type that does not have integer values should return null.
      Parameters:
      query - The TopN query being served
      params - Parameters for the TopN query being served
      cursorInspector - provide information about the cursor that can be used for query optimization, e.g. whether dimension values are sorted or not
      Returns:
      an Aggregator[][] for integer-valued dimensions, null otherwise
    • scanAndAggregate

      long scanAndAggregate(TopNQuery query, ValueSelectorType selector, Cursor cursor, CursorGranularizer granularizer, Aggregator[][] rowSelector)
      Used by HeapBasedTopNAlgorithm. The contract of this method requires calling initAggregateStore() prior to calling this method. Iterate through the Cursor, reading the current row from a dimension value selector, and for each row value: 1. Retrieve the Aggregator[] for the row value from rowSelector (fast integer lookup), usable if value cardinality is known, or from aggregatesStore (slower map). 2. If the rowSelector/aggregatesStore did not have an entry for a particular row value, this function should retrieve the current Aggregator[] using BaseTopNAlgorithm.makeAggregators(org.apache.druid.segment.Cursor, java.util.List<org.apache.druid.query.aggregation.AggregatorFactory>) and the provided cursor and query, storing them in rowSelector/aggregatesStore 3. Call Aggregator.aggregate() on each of the aggregators. If a dimension type doesn't have integer values, it should ignore rowSelector and use the aggregatesStore map only.
      Parameters:
      query - The TopN query being served.
      selector - Dimension value selector
      cursor - Cursor for the segment being queried
      rowSelector - Integer lookup containing aggregators
      Returns:
      the number of processed rows (after postFilters are applied inside the cursor being processed)
    • updateResults

      void updateResults(TopNResultBuilder resultBuilder)
      Used by HeapBasedTopNAlgorithm. Read entries from the aggregates store, adding the keys and associated values to the resultBuilder, applying the valueTransformer to the keys if present
      Parameters:
      resultBuilder - TopN result builder
    • initAggregateStore

      void initAggregateStore()
      Initializes the underlying aggregates store to something nice and seleector type appropriate
    • closeAggregators

      void closeAggregators()
      Closes all on heap Aggregator associated with the aggregates processor