Class FallbackVirtualColumn
- java.lang.Object
-
- org.apache.druid.segment.virtual.FallbackVirtualColumn
-
- All Implemented Interfaces:
Cacheable
,VirtualColumn
public class FallbackVirtualColumn extends Object implements VirtualColumn
A virtual column that picks one column or another based on whether they exist. It walks through an array of DimensionSpecs finding and using the first column that actually exists. If it believes that none of them exist it YOLOs it with the first entry from the list.If you are using this virtual column and want to have a decorator/extraction function on your DimensionSpec, it is expected that you will put it on the specs in the list rather than on the spec that references this virtual column. That is, when this virtual column resolves a dimension, it ignores the decoration from the spec that it was given and instead uses the spec as defined in the list as-is to delegate to the column that it chose.
-
-
Constructor Summary
Constructors Constructor Description FallbackVirtualColumn(String name, ArrayList<DimensionSpec> columns)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canVectorize(ColumnInspector inspector)
ColumnCapabilities
capabilities(String columnName)
This method is deprecated in favor ofVirtualColumn.capabilities(ColumnInspector, String)
, which should be used whenever possible and can support virtual column implementations that need to inspect other columns as inputs.ColumnCapabilities
capabilities(ColumnInspector inspector, String columnName)
Return theColumnCapabilities
which best describe the optimal selector to read from this virtual column.byte[]
getCacheKey()
Get a byte array used as a cache key.ArrayList<DimensionSpec>
getColumns()
ColumnIndexSupplier
getIndexSupplier(String columnName, ColumnSelector columnSelector)
Get theColumnIndexSupplier
for the specified virtual column, with the assistance of aColumnSelector
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.DimensionSelector
makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)
Build a selector corresponding to this virtual column.MultiValueDimensionVectorSelector
makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aMultiValueDimensionVectorSelector
corresponding to this virtual column.SingleValueDimensionVectorSelector
makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Build aSingleValueDimensionVectorSelector
corresponding to this virtual column.VectorObjectSelector
makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory factory)
Build aVectorObjectSelector
corresponding to this virtual column.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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.segment.VirtualColumn
makeColumnValueSelector, makeDimensionSelector, makeMultiValueVectorDimensionSelector, makeSingleValueVectorDimensionSelector, makeVectorObjectSelector, makeVectorValueSelector
-
-
-
-
Constructor Detail
-
FallbackVirtualColumn
public FallbackVirtualColumn(String name, ArrayList<DimensionSpec> columns)
-
-
Method Detail
-
getOutputName
public String getOutputName()
Description copied from interface:VirtualColumn
Output name of this column.- Specified by:
getOutputName
in interfaceVirtualColumn
- Returns:
- name
-
getColumns
public ArrayList<DimensionSpec> getColumns()
-
getCacheKey
public byte[] getCacheKey()
Description copied from interface:Cacheable
Get a byte array used as a cache key.- Specified by:
getCacheKey
in interfaceCacheable
- Returns:
- a cache key
-
makeDimensionSelector
public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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.- Specified by:
makeDimensionSelector
in interfaceVirtualColumn
-
makeColumnValueSelector
public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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.- Specified by:
makeColumnValueSelector
in interfaceVirtualColumn
-
canVectorize
public boolean canVectorize(ColumnInspector inspector)
- Specified by:
canVectorize
in interfaceVirtualColumn
-
makeSingleValueVectorDimensionSelector
public SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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
.- Specified by:
makeSingleValueVectorDimensionSelector
in interfaceVirtualColumn
-
makeMultiValueVectorDimensionSelector
public MultiValueDimensionVectorSelector makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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
.- Specified by:
makeMultiValueVectorDimensionSelector
in interfaceVirtualColumn
-
makeVectorValueSelector
public VectorValueSelector makeVectorValueSelector(String columnName, VectorColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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.- Specified by:
makeVectorValueSelector
in interfaceVirtualColumn
-
makeVectorObjectSelector
public VectorObjectSelector makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory factory)
Description copied from interface:VirtualColumn
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.- Specified by:
makeVectorObjectSelector
in interfaceVirtualColumn
-
capabilities
public ColumnCapabilities capabilities(String columnName)
Description copied from interface:VirtualColumn
This method is deprecated in favor ofVirtualColumn.capabilities(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 fromVirtualColumn.makeColumnValueSelector(String, ColumnSelectorFactory)
. May vary based on columnName if this column uses dot notation.- Specified by:
capabilities
in interfaceVirtualColumn
- Parameters:
columnName
- the name this virtual column was referenced with- Returns:
- capabilities, must not be null
-
capabilities
@Nullable public ColumnCapabilities capabilities(ColumnInspector inspector, String columnName)
Description copied from interface:VirtualColumn
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.- Specified by:
capabilities
in interfaceVirtualColumn
- 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
public List<String> requiredColumns()
Description copied from interface:VirtualColumn
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.- Specified by:
requiredColumns
in interfaceVirtualColumn
- Returns:
- column names
-
usesDotNotation
public boolean usesDotNotation()
Description copied from interface:VirtualColumn
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".- Specified by:
usesDotNotation
in interfaceVirtualColumn
- Returns:
- whether to use dot notation
-
getIndexSupplier
@Nullable public ColumnIndexSupplier getIndexSupplier(String columnName, ColumnSelector columnSelector)
Description copied from interface:VirtualColumn
Get theColumnIndexSupplier
for the specified virtual column, with the assistance of aColumnSelector
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.- Specified by:
getIndexSupplier
in interfaceVirtualColumn
-
-