Class SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector
- java.lang.Object
-
- org.apache.druid.segment.virtual.SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector
-
- All Implemented Interfaces:
DimensionDictionarySelector,SingleValueDimensionVectorSelector,VectorSizeInspector
public class SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector extends Object implements SingleValueDimensionVectorSelector
ASingleValueDimensionVectorSelectordecorator that directly exposes the underlying dictionary ids ingetRowVector(), saving expression computation untillookupName(int)is called. This allows for performing operations like grouping on the native dictionary ids, and deferring expression evaluation until after, which can dramatically reduce the total number of evaluations.
-
-
Field Summary
-
Fields inherited from interface org.apache.druid.segment.DimensionDictionarySelector
CARDINALITY_UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector(SingleValueDimensionVectorSelector selector, Expr expression)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCurrentVectorSize()Returns the current vector size for this cursor.intgetMaxVectorSize()Returns the maximum vector size for this cursor.int[]getRowVector()Get the current vector.intgetValueCardinality()Value cardinality is the cardinality of the different occurring values.IdLookupidLookup()ReturnsIdLookupif available for this DimensionSelector, or null.StringlookupName(int id)Returns the value for a particular dictionary id as a Java String.booleannameLookupPossibleInAdvance()Returns true if it is possible toDimensionDictionarySelector.lookupName(int)by ids from 0 toDimensionDictionarySelector.getValueCardinality()before the rows with those ids are returned.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.segment.DimensionDictionarySelector
lookupNameUtf8, supportsLookupNameUtf8
-
-
-
-
Constructor Detail
-
SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector
public SingleStringInputDeferredEvaluationExpressionDimensionVectorSelector(SingleValueDimensionVectorSelector selector, Expr expression)
-
-
Method Detail
-
getValueCardinality
public int getValueCardinality()
Description copied from interface:DimensionDictionarySelectorValue cardinality is the cardinality of the different occurring values. If there were 4 rows: A,B A B A Value cardinality would be 2. Cardinality may be unknown (e.g. the selector used by IncrementalIndex while reading input rows), in which case this method will return -1. If cardinality is unknown, you should assume this dimension selector has no dictionary, and avoid storing ids, calling "lookupId", or calling "lookupName" outside of the context of operating on a single row. If cardinality is known then it is assumed that underlying dictionary is lexicographically sorted by the encoded value. For example if there are values "A" , "B" , "C" in a column with cardinality 3 then it is assumed that id("A") < id("B") < id("C")- Specified by:
getValueCardinalityin interfaceDimensionDictionarySelector- Returns:
- the value cardinality, or
DimensionDictionarySelector.CARDINALITY_UNKNOWNif unknown.
-
lookupName
@Nullable public String lookupName(int id)
Description copied from interface:DimensionDictionarySelectorReturns the value for a particular dictionary id as a Java String. For example, if a column has four rows: A,B A A,B B getRow() would return getRow(0) => [0 1] getRow(1) => [0] getRow(2) => [0 1] getRow(3) => [1] and then lookupName would return: lookupName(0) => A lookupName(1) => B Performance note: if you want ajava.lang.String, always use this method. It will be at least as fast as callingDimensionDictionarySelector.lookupNameUtf8(int)and decoding the bytes. However, if you want UTF-8 bytes, then check ifDimensionDictionarySelector.supportsLookupNameUtf8()returns true, and if it does, useDimensionDictionarySelector.lookupNameUtf8(int)instead.- Specified by:
lookupNamein interfaceDimensionDictionarySelector- Parameters:
id- id to lookup the dictionary value for- Returns:
- dictionary value for the given id, or null if the value is itself null
-
nameLookupPossibleInAdvance
public boolean nameLookupPossibleInAdvance()
Description copied from interface:DimensionDictionarySelectorReturns true if it is possible toDimensionDictionarySelector.lookupName(int)by ids from 0 toDimensionDictionarySelector.getValueCardinality()before the rows with those ids are returned.Returns false if
DimensionDictionarySelector.lookupName(int)could be called with ids, returned from the most recent row (or row vector) returned by this DimensionSelector, but not earlier. IfDimensionDictionarySelector.getValueCardinality()of this selector additionally returnsDimensionDictionarySelector.CARDINALITY_UNKNOWN,lookupName()couldn't be called with ids, returned by not the most recent row (or row vector), i. e. names for ids couldn't be looked up "later". IfDimensionDictionarySelector.getValueCardinality()returns a non-negative number,lookupName()could be called with any ids, returned from rows (or row vectors) returned since the creation of this DimensionSelector.If
DimensionDictionarySelector.lookupName(int)is called with an ineligible id, result is undefined: exception could be thrown, or null returned, or some other random value.- Specified by:
nameLookupPossibleInAdvancein interfaceDimensionDictionarySelector
-
idLookup
@Nullable public IdLookup idLookup()
Description copied from interface:DimensionDictionarySelectorReturnsIdLookupif available for this DimensionSelector, or null.- Specified by:
idLookupin interfaceDimensionDictionarySelector
-
getRowVector
public int[] getRowVector()
Description copied from interface:SingleValueDimensionVectorSelectorGet the current vector. The array will be reused, so it is not a good idea to retain a reference to it.- Specified by:
getRowVectorin interfaceSingleValueDimensionVectorSelector
-
getMaxVectorSize
public int getMaxVectorSize()
Description copied from interface:VectorSizeInspectorReturns the maximum vector size for this cursor. It will not change for the lifetime of this cursor, and is generally used to allocate scratch arrays for later processing. Will always be greater than zero.- Specified by:
getMaxVectorSizein interfaceVectorSizeInspector
-
getCurrentVectorSize
public int getCurrentVectorSize()
Description copied from interface:VectorSizeInspectorReturns the current vector size for this cursor. Will never be larger than the max size returned byVectorSizeInspector.getMaxVectorSize().- Specified by:
getCurrentVectorSizein interfaceVectorSizeInspector
-
-