Package org.apache.druid.segment
Interface VirtualColumn
-
- All Superinterfaces:
Cacheable
- All Known Implementing Classes:
ExpressionVirtualColumn
,FallbackVirtualColumn
,ListFilteredVirtualColumn
,NestedFieldVirtualColumn
,SettableLongVirtualColumn
public interface VirtualColumn extends Cacheable
Virtual columns are "views" created over aColumnSelectorFactory
orColumnSelector
. They can potentially draw from multiple underlying columns, although they always present themselves as if they were a single column. A virtual column object will be shared amongst threads and must be thread safe. The selectors returned from the various makeXXXSelector methods need not be thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
VirtualColumn.EquivalenceKey
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default boolean
canVectorize(ColumnInspector inspector)
ColumnCapabilities
capabilities(String columnName)
Deprecated.default ColumnCapabilities
capabilities(ColumnInspector inspector, String columnName)
Return theColumnCapabilities
which best describe the optimal selector to read from this virtual column.default VirtualColumn.EquivalenceKey
getEquivalanceKey()
Returns a key used for "equivalence" comparisons, for checking if some virtual column is equivalent to some other virtual column, regardless of the output name.default ColumnIndexSupplier
getIndexSupplier(String columnName, ColumnIndexSelector columnIndexSelector)
Get theColumnIndexSupplier
for the specified virtual column, with the assistance of aColumnIndexSelector
to allow reading things from segments.String
getOutputName()
Output name of this column.ColumnValueSelector<?>
makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)
Build aColumnValueSelector
corresponding to this virtual column.default ColumnValueSelector<?>
makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarColumnValueSelector
object as returned bymakeColumnValueSelector(String, ColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.DimensionSelector
makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)
Build a selector corresponding to this virtual column.default DimensionSelector
makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarDimensionSelector
object as returned bymakeDimensionSelector(DimensionSpec, ColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.default GroupByVectorColumnSelector
makeGroupByVectorColumnSelector(String columnName, VectorColumnSelectorFactory factory, DeferExpressionDimensions deferExpressionDimensions)
Returns a group-by selector.default MultiValueDimensionVectorSelector
makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarSingleValueDimensionVectorSelector
object as returned bymakeSingleValueVectorDimensionSelector(DimensionSpec, ColumnSelector, ReadableVectorOffset)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.default MultiValueDimensionVectorSelector
makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aMultiValueDimensionVectorSelector
corresponding to this virtual column.default SingleValueDimensionVectorSelector
makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarSingleValueDimensionVectorSelector
object as returned bymakeSingleValueVectorDimensionSelector(DimensionSpec, ColumnSelector, ReadableVectorOffset)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.default SingleValueDimensionVectorSelector
makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aSingleValueDimensionVectorSelector
corresponding to this virtual column.default VectorObjectSelector
makeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorObjectSelector
object as returned bymakeVectorObjectSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.default VectorObjectSelector
makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory factory)
Build aVectorObjectSelector
corresponding to this virtual column.default VectorValueSelector
makeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorValueSelector
object as returned bymakeVectorValueSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.default VectorValueSelector
makeVectorValueSelector(String columnName, VectorColumnSelectorFactory factory)
Build aVectorValueSelector
corresponding to this virtual column.List<String>
requiredColumns()
Returns a list of columns that this virtual column will access.boolean
usesDotNotation()
Indicates that this virtual column can be referenced with dot notation.-
Methods inherited from interface org.apache.druid.java.util.common.Cacheable
getCacheKey
-
-
-
-
Method Detail
-
getOutputName
String getOutputName()
Output name of this column.- Returns:
- name
-
makeDimensionSelector
DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)
Build a selector corresponding to this virtual column. Also provides the name that the virtual column was referenced with (throughDimensionSpec.getDimension()
, which is useful if this column uses dot notation. The virtual column is expected to apply any necessary decoration from the dimensionSpec.
-
makeDimensionSelector
@Nullable default DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarDimensionSelector
object as returned bymakeDimensionSelector(DimensionSpec, ColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible. Typically this can not be called in query paths on top of IncrementalIndex which doesn't have columns as in persisted segments.
-
makeColumnValueSelector
ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)
Build aColumnValueSelector
corresponding to this virtual column. Also provides the name that the virtual column was referenced with, which is useful if this column uses dot notation.
-
makeColumnValueSelector
@Nullable default ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarColumnValueSelector
object as returned bymakeColumnValueSelector(String, ColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible. Typically this can not be called in query paths on top of IncrementalIndex which doesn't have columns as in persisted segments.
-
canVectorize
default boolean canVectorize(ColumnInspector inspector)
-
makeSingleValueVectorDimensionSelector
default SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aSingleValueDimensionVectorSelector
corresponding to this virtual column. Also provides the name that the virtual column was referenced with (throughDimensionSpec.getDimension()
, which is useful if this column uses dot notation. The virtual column is expected to apply any necessary decoration from theDimensionSpec
.
-
makeSingleValueVectorDimensionSelector
@Nullable default SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarSingleValueDimensionVectorSelector
object as returned bymakeSingleValueVectorDimensionSelector(DimensionSpec, ColumnSelector, ReadableVectorOffset)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible.
-
makeMultiValueVectorDimensionSelector
default MultiValueDimensionVectorSelector makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aMultiValueDimensionVectorSelector
corresponding to this virtual column. Also provides the name that the virtual column was referenced with (throughDimensionSpec.getDimension()
, which is useful if this column uses dot notation. The virtual column is expected to apply any necessary decoration from theDimensionSpec
.
-
makeMultiValueVectorDimensionSelector
@Nullable default MultiValueDimensionVectorSelector makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarSingleValueDimensionVectorSelector
object as returned bymakeSingleValueVectorDimensionSelector(DimensionSpec, ColumnSelector, ReadableVectorOffset)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible.
-
makeVectorValueSelector
default VectorValueSelector makeVectorValueSelector(String columnName, VectorColumnSelectorFactory factory)
Build aVectorValueSelector
corresponding to this virtual column. Also provides the name that the virtual column was referenced with, which is useful if this column uses dot notation.
-
makeVectorValueSelector
@Nullable default VectorValueSelector makeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorValueSelector
object as returned bymakeVectorValueSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible.
-
makeVectorObjectSelector
default VectorObjectSelector makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory factory)
Build aVectorObjectSelector
corresponding to this virtual column. Also provides the name that the virtual column was referenced with, which is useful if this column uses dot notation.
-
makeVectorObjectSelector
@Nullable default VectorObjectSelector makeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorObjectSelector
object as returned bymakeVectorObjectSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation. Users of this interface must ensure to first call this method whenever possible.
-
makeGroupByVectorColumnSelector
@Nullable default GroupByVectorColumnSelector makeGroupByVectorColumnSelector(String columnName, VectorColumnSelectorFactory factory, DeferExpressionDimensions deferExpressionDimensions)
Returns a group-by selector. Allows virtual columns to control their own grouping behavior.- Parameters:
columnName
- column namefactory
- column selector factorydeferExpressionDimensions
- active value ofGroupByQueryConfig.CTX_KEY_DEFER_EXPRESSION_DIMENSIONS
- Returns:
- selector, or null if this virtual column does not have a specialized one
-
capabilities
@Deprecated ColumnCapabilities capabilities(String columnName)
Deprecated.This method is deprecated in favor ofcapabilities(ColumnInspector, String)
, which should be used whenever possible and can support virtual column implementations that need to inspect other columns as inputs. This is a fallback implementation to return the capabilities of this virtual column, which includes a type that corresponds to the best performing base selector supertype (e. g.BaseLongColumnValueSelector
) of the object, returned frommakeColumnValueSelector(String, ColumnSelectorFactory)
. May vary based on columnName if this column uses dot notation.- Parameters:
columnName
- the name this virtual column was referenced with- Returns:
- capabilities, must not be null
-
capabilities
@Nullable default ColumnCapabilities capabilities(ColumnInspector inspector, String columnName)
Return theColumnCapabilities
which best describe the optimal selector to read from this virtual column.The
ColumnInspector
(most likely corresponding to an underlyingColumnSelectorFactory
of a query) allows the virtual column to consider this information if necessary to compute its output type details.Examples of this include the
ExpressionVirtualColumn
, which takes input from other columns and uses theColumnInspector
to infer the output type of expressions based on the types of the inputs.- Parameters:
inspector
- column inspector to provide additional information of other available columnscolumnName
- the name this virtual column was referenced with- Returns:
- capabilities, must not be null
-
requiredColumns
List<String> requiredColumns()
Returns a list of columns that this virtual column will access. This may include the names of other virtual columns. May be empty if a virtual column doesn't access any underlying columns. Does not pass columnName because there is an assumption that the list of columns needed by a dot-notation supporting virtual column will not vary based on the columnName.- Returns:
- column names
-
usesDotNotation
boolean usesDotNotation()
Indicates that this virtual column can be referenced with dot notation. For example, a virtual column named "foo" could be referred to as "foo.bar" with the Cursor it is registered with. In that case, init will be called with columnName "foo.bar" rather than "foo".- Returns:
- whether to use dot notation
-
getIndexSupplier
@Nullable default ColumnIndexSupplier getIndexSupplier(String columnName, ColumnIndexSelector columnIndexSelector)
Get theColumnIndexSupplier
for the specified virtual column, with the assistance of aColumnIndexSelector
to allow reading things from segments. If the virtual column has no indexes, this method will return null, or may also return a non-null supplier whose methods may return null values - having a supplier is no guarantee that the column has indexes.
-
getEquivalanceKey
@Nullable default VirtualColumn.EquivalenceKey getEquivalanceKey()
Returns a key used for "equivalence" comparisons, for checking if some virtual column is equivalent to some other virtual column, regardless of the output name. If this method returns null, it does not participate in equivalence comparisons.
-
-