Class FixedWidthGroupByColumnSelectorStrategy<T>

java.lang.Object
org.apache.druid.query.groupby.epinephelinae.column.FixedWidthGroupByColumnSelectorStrategy<T>
Type Parameters:
T - Class of the dimension
All Implemented Interfaces:
ColumnSelectorStrategy, GroupByColumnSelectorStrategy

@NotThreadSafe public class FixedWidthGroupByColumnSelectorStrategy<T> extends Object implements GroupByColumnSelectorStrategy
Strategy for grouping dimensions which have fixed-width objects. It is only used for numeric primitive types, however complex types can reuse this strategy if they can hint the engine that they are always fixed width (for e.g. IP types). Such types donot need to be backed by a dictionary, and hence are faster to group by.
  • Constructor Details

  • Method Details

    • getGroupingKeySizeBytes

      public int getGroupingKeySizeBytes()
      Description copied from interface: GroupByColumnSelectorStrategy
      Return the size, in bytes, of this dimension's values in the grouping key. For example, a String implementation would return 4, the size of an int.
      Specified by:
      getGroupingKeySizeBytes in interface GroupByColumnSelectorStrategy
      Returns:
      size, in bytes, of this dimension's values in the grouping key.
    • processValueFromGroupingKey

      public void processValueFromGroupingKey(GroupByColumnSelectorPlus selectorPlus, ByteBuffer key, ResultRow resultRow, int keyBufferPosition)
      Description copied from interface: GroupByColumnSelectorStrategy
      Read a value from a grouping key and add it to the group by query result row, using the output name specified in a DimensionSpec. An implementation may choose to not add anything to the result row (e.g., as the String implementation does for empty rows) selectorPlus provides access to: - the keyBufferPosition offset from which to read the value - the dimension value selector - the DimensionSpec for this dimension from the query
      Specified by:
      processValueFromGroupingKey in interface GroupByColumnSelectorStrategy
      Parameters:
      selectorPlus - dimension info containing the key offset, value selector, and dimension spec
      key - grouping key
      resultRow - result row for the group by query being served
      keyBufferPosition - buffer position for the grouping key, added to support chaining multiple ColumnSelectorStrategy
    • initColumnValues

      public int initColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess)
      Description copied from interface: GroupByColumnSelectorStrategy
      Retrieve a row object from the ColumnValueSelector and put it in valuess at columnIndex.
      Specified by:
      initColumnValues in interface GroupByColumnSelectorStrategy
      Parameters:
      selector - Value selector for a column.
      columnIndex - Index of the column within the row values array
      valuess - Row values array, one index per column
      Returns:
      estimated increase in internal state footprint, in bytes, as a result of this operation. May be zero if memory did not increase as a result of this operation. Will not be negative.
    • initGroupingKeyColumnValue

      public void initGroupingKeyColumnValue(int keyBufferPosition, int dimensionIndex, Object rowObj, ByteBuffer keyBuffer, int[] stack)
      Description copied from interface: GroupByColumnSelectorStrategy
      Read the first value within a row values object (e. g. IndexedInts, as the value in a dictionary-encoded string column) and write that value to the keyBuffer at keyBufferPosition. If the row size is 0 (e. g. IndexedInts.size()), write GroupByColumnSelectorStrategy.GROUP_BY_MISSING_VALUE instead. If the size of the row is > 0, write 1 to stack[] at columnIndex, otherwise write 0.
      Specified by:
      initGroupingKeyColumnValue in interface GroupByColumnSelectorStrategy
      Parameters:
      keyBufferPosition - Starting offset for this column's value within the grouping key.
      dimensionIndex - Index of this dimension within the stack array
      rowObj - Row value object for this column
      keyBuffer - grouping key
      stack - array containing the current within-row value index for each column
    • checkRowIndexAndAddValueToGroupingKey

      public boolean checkRowIndexAndAddValueToGroupingKey(int keyBufferPosition, Object rowObj, int rowValIdx, ByteBuffer keyBuffer)
      This is used for multi-valued dimensions, for values after the first one. None of the current types supported by this strategy handle multi-valued dimensions, therefore this short circuits and returns false
      Specified by:
      checkRowIndexAndAddValueToGroupingKey in interface GroupByColumnSelectorStrategy
      Parameters:
      keyBufferPosition - Starting offset for this column's value within the grouping key.
      rowObj - Row value object for this column (e.g., IndexedInts)
      rowValIdx - Index of the current value being grouped on within the row
      keyBuffer - grouping key
      Returns:
      true if rowValIdx < size of rowObj, false otherwise
    • writeToKeyBuffer

      public int writeToKeyBuffer(int keyBufferPosition, ColumnValueSelector selector, ByteBuffer keyBuffer)
      Description copied from interface: GroupByColumnSelectorStrategy
      Write a single object from the given selector to the keyBuffer at keyBufferPosition. The reading column must have a single value. The position of the keyBuffer may be modified.
      Specified by:
      writeToKeyBuffer in interface GroupByColumnSelectorStrategy
      Parameters:
      keyBufferPosition - starting offset for this column's value within the grouping key
      selector - selector to retrieve row value object from
      keyBuffer - grouping key
      Returns:
      estimated increase in internal state footprint, in bytes, as a result of this operation. May be zero if memory did not increase as a result of this operation. Will not be negative.
    • bufferComparator

      public Grouper.BufferComparator bufferComparator(int keyBufferPosition, @Nullable StringComparator stringComparator)
      Description copied from interface: GroupByColumnSelectorStrategy
      Return BufferComparator for values written using this strategy when limit is pushed down to segment scan.
      Specified by:
      bufferComparator in interface GroupByColumnSelectorStrategy
      Parameters:
      keyBufferPosition - starting offset for this column's value within the grouping key
      stringComparator - stringComparator from LimitSpec for this column. If this is null, implementations will use the StringComparators.LEXICOGRAPHIC comparator.
      Returns:
      BufferComparator for comparing values written
    • reset

      public void reset()
      Description copied from interface: GroupByColumnSelectorStrategy
      Reset any internal state held by this selector. After this method is called, any row objects or key objects generated by any methods of this class must be considered unreadable. Calling GroupByColumnSelectorStrategy.processValueFromGroupingKey(org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus, java.nio.ByteBuffer, org.apache.druid.query.groupby.ResultRow, int) on that memory has undefined behavior.
      Specified by:
      reset in interface GroupByColumnSelectorStrategy