Class DictionaryBuildingGroupByColumnSelectorStrategy<DimensionType>
- java.lang.Object
-
- org.apache.druid.query.groupby.epinephelinae.column.DictionaryBuildingGroupByColumnSelectorStrategy<DimensionType>
-
- All Implemented Interfaces:
ColumnSelectorStrategy,GroupByColumnSelectorStrategy
@NotThreadSafe public class DictionaryBuildingGroupByColumnSelectorStrategy<DimensionType> extends Object
Strategy for grouping dimensions which can have variable-width objects, and aren't backed by prebuilt dictionaries. It encapsulates the dictionary building logic, along with providing the implementations for dimension to dictionary id encoding-decoding.This strategy can handle any dimension that can be addressed on a reverse-dictionary. Reverse dictionary uses a sorted map, rather than a hashmap.
This is the most expensive of all the strategies, and hence must be used only when other strategies aren't valid.
-
-
Field Summary
-
Fields inherited from interface org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorStrategy
GROUP_BY_MISSING_VALUE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Grouper.BufferComparatorbufferComparator(int keyBufferPosition, StringComparator stringComparator)Return BufferComparator for values written using this strategy when limit is pushed down to segment scan.booleancheckRowIndexAndAddValueToGroupingKey(int keyBufferPosition, Object rowObj, int rowValIdx, ByteBuffer keyBuffer)If rowValIdx is less than the size of rowObj (haven't handled all of the row values): First, read the value at rowValIdx from a rowObj and write that value to the keyBuffer at keyBufferPosition.static GroupByColumnSelectorStrategyforType(ColumnType columnType)Creates an implementation of the strategy for the given typeintgetGroupingKeySizeBytes()Strategy maps to integer dictionary idsintinitColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess)Retrieve a row object from theColumnValueSelectorand put it in valuess at columnIndex.voidinitGroupingKeyColumnValue(int keyBufferPosition, int dimensionIndex, Object rowObj, ByteBuffer keyBuffer, int[] stack)Read the first value within a row values object (e.voidprocessValueFromGroupingKey(GroupByColumnSelectorPlus selectorPlus, ByteBuffer key, ResultRow resultRow, int keyBufferPosition)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.voidreset()Reset any internal state held by this selector.intwriteToKeyBuffer(int keyBufferPosition, ColumnValueSelector selector, ByteBuffer keyBuffer)Write a single object from the given selector to the keyBuffer at keyBufferPosition.
-
-
-
Method Detail
-
forType
public static GroupByColumnSelectorStrategy forType(ColumnType columnType)
Creates an implementation of the strategy for the given type
-
getGroupingKeySizeBytes
public int getGroupingKeySizeBytes()
Strategy maps to integer dictionary ids- Specified by:
getGroupingKeySizeBytesin interfaceGroupByColumnSelectorStrategy- 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:GroupByColumnSelectorStrategyRead 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:
processValueFromGroupingKeyin interfaceGroupByColumnSelectorStrategy- Parameters:
selectorPlus- dimension info containing the key offset, value selector, and dimension speckey- grouping keyresultRow- result row for the group by query being servedkeyBufferPosition- buffer position for the grouping key, added to support chaining multipleColumnSelectorStrategy
-
initColumnValues
public int initColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess)
Description copied from interface:GroupByColumnSelectorStrategyRetrieve a row object from theColumnValueSelectorand put it in valuess at columnIndex.- Specified by:
initColumnValuesin interfaceGroupByColumnSelectorStrategy- Parameters:
selector- Value selector for a column.columnIndex- Index of the column within the row values arrayvaluess- 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:GroupByColumnSelectorStrategyRead 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()), writeGroupByColumnSelectorStrategy.GROUP_BY_MISSING_VALUEinstead. If the size of the row is > 0, write 1 to stack[] at columnIndex, otherwise write 0.- Specified by:
initGroupingKeyColumnValuein interfaceGroupByColumnSelectorStrategy- Parameters:
keyBufferPosition- Starting offset for this column's value within the grouping key.dimensionIndex- Index of this dimension within thestackarrayrowObj- Row value object for this columnkeyBuffer- grouping keystack- array containing the current within-row value index for each column
-
checkRowIndexAndAddValueToGroupingKey
public boolean checkRowIndexAndAddValueToGroupingKey(int keyBufferPosition, Object rowObj, int rowValIdx, ByteBuffer keyBuffer)Description copied from interface:GroupByColumnSelectorStrategyIf rowValIdx is less than the size of rowObj (haven't handled all of the row values): First, read the value at rowValIdx from a rowObj and write that value to the keyBuffer at keyBufferPosition. Then return true. This method assumes that the size increase associated with the dictionary building has occurred already when callingGroupByColumnSelectorStrategy.initColumnValues(org.apache.druid.segment.ColumnValueSelector, int, java.lang.Object[])Otherwise, return false.- Specified by:
checkRowIndexAndAddValueToGroupingKeyin interfaceGroupByColumnSelectorStrategy- 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 rowkeyBuffer- 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:GroupByColumnSelectorStrategyWrite 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:
writeToKeyBufferin interfaceGroupByColumnSelectorStrategy- Parameters:
keyBufferPosition- starting offset for this column's value within the grouping keyselector- selector to retrieve row value object fromkeyBuffer- 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:GroupByColumnSelectorStrategyReturn BufferComparator for values written using this strategy when limit is pushed down to segment scan.- Specified by:
bufferComparatorin interfaceGroupByColumnSelectorStrategy- Parameters:
keyBufferPosition- starting offset for this column's value within the grouping keystringComparator- stringComparator from LimitSpec for this column. If this is null, implementations will use theStringComparators.LEXICOGRAPHICcomparator.- Returns:
- BufferComparator for comparing values written
-
reset
public void reset()
Description copied from interface:GroupByColumnSelectorStrategyReset 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. CallingGroupByColumnSelectorStrategy.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:
resetin interfaceGroupByColumnSelectorStrategy
-
-