Class NestedFieldVirtualColumn
- java.lang.Object
-
- org.apache.druid.segment.virtual.NestedFieldVirtualColumn
-
- All Implemented Interfaces:
Cacheable
,VirtualColumn
public class NestedFieldVirtualColumn extends Object implements VirtualColumn
Optimized virtual column that can make direct selectors into aNestedDataComplexColumn
or any associated nested fields (NestedFieldDictionaryEncodedColumn
) including using their indexes.This virtual column is used for the SQL operators JSON_VALUE (if
processFromRaw
is set to false) or JSON_QUERY (if it is true), and accepts 'JSONPath' or 'jq' syntax string representations of paths, or a parsed list ofNestedPathPart
in order to determine what should be selected from the column.Type information for nested fields is completely absent in the SQL planner, so it guesses the best it can to set
expectedType
from the context of how something is being used, e.g. an aggregators default type or an explicit cast, or, if using the 'RETURNING' syntax which explicitly specifies type. This might not be the same as if it had actual type information, but, we try to stick with whatever we chose there to do the best we can for now.Since
capabilities(ColumnInspector, String)
is determined by theexpectedType
, the results will be best effor cast to the expected type if the column is not natively the expected type so that this column can fulfill the contract of the type of selector that is likely to be created to read this column.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NestedFieldVirtualColumn.FieldDimensionSelector
static class
NestedFieldVirtualColumn.RawFieldColumnSelector
Process the "raw" data to extract values withNestedPathFinder.find(Object, List)
, wrapping the result inStructuredData
static class
NestedFieldVirtualColumn.RawFieldLiteralColumnValueSelector
Process the "raw" data to extract non-complex values.static class
NestedFieldVirtualColumn.RawFieldVectorObjectSelector
Process the "raw" data to extract vectors of values withNestedPathFinder.find(Object, List)
, wrapping the result inStructuredData
-
Constructor Summary
Constructors Constructor Description NestedFieldVirtualColumn(String columnName, String path, String outputName)
NestedFieldVirtualColumn(String columnName, String path, String outputName, ColumnType expectedType)
NestedFieldVirtualColumn(String columnName, String outputName, ColumnType expectedType, List<NestedPathPart> parts, Boolean processFromRaw, String path, Boolean useJqSyntax)
-
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.boolean
equals(Object o)
byte[]
getCacheKey()
Get a byte array used as a cache key.String
getColumnName()
ColumnType
getExpectedType()
ColumnIndexSupplier
getIndexSupplier(String columnName, ColumnSelector selector)
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.List<NestedPathPart>
getPathParts()
int
hashCode()
boolean
isProcessFromRaw()
ColumnValueSelector<?>
makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)
Build aColumnValueSelector
corresponding to this virtual column.ColumnValueSelector<?>
makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarColumnValueSelector
object as returned byVirtualColumn.makeColumnValueSelector(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.DimensionSelector
makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)
Returns similarDimensionSelector
object as returned byVirtualColumn.makeDimensionSelector(DimensionSpec, ColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.SingleValueDimensionVectorSelector
makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarSingleValueDimensionVectorSelector
object as returned byVirtualColumn.makeSingleValueVectorDimensionSelector(DimensionSpec, ColumnSelector, ReadableVectorOffset)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.VectorObjectSelector
makeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorObjectSelector
object as returned byVirtualColumn.makeVectorObjectSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.VectorValueSelector
makeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Returns similarVectorValueSelector
object as returned byVirtualColumn.makeVectorValueSelector(String, VectorColumnSelectorFactory)
except this method has full access to the underlying column and can potentially provide a more efficient implementation.List<String>
requiredColumns()
Returns a list of columns that this virtual column will access.String
toString()
boolean
usesDotNotation()
Indicates that this virtual column can be referenced with dot notation.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.druid.segment.VirtualColumn
makeMultiValueVectorDimensionSelector, makeMultiValueVectorDimensionSelector, makeSingleValueVectorDimensionSelector, makeVectorObjectSelector, makeVectorValueSelector
-
-
-
-
Constructor Detail
-
NestedFieldVirtualColumn
public NestedFieldVirtualColumn(String columnName, String outputName, @Nullable ColumnType expectedType, @Nullable List<NestedPathPart> parts, @Nullable Boolean processFromRaw, @Nullable String path, @Nullable Boolean useJqSyntax)
-
NestedFieldVirtualColumn
public NestedFieldVirtualColumn(String columnName, String path, String outputName)
-
NestedFieldVirtualColumn
public NestedFieldVirtualColumn(String columnName, String path, String outputName, @Nullable ColumnType expectedType)
-
-
Method Detail
-
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
-
getOutputName
public String getOutputName()
Description copied from interface:VirtualColumn
Output name of this column.- Specified by:
getOutputName
in interfaceVirtualColumn
- Returns:
- name
-
getColumnName
public String getColumnName()
-
getPathParts
public List<NestedPathPart> getPathParts()
-
getExpectedType
public ColumnType getExpectedType()
-
isProcessFromRaw
public boolean isProcessFromRaw()
-
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
-
makeDimensionSelector
@Nullable public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)
Description copied from interface:VirtualColumn
Returns similarDimensionSelector
object as returned byVirtualColumn.makeDimensionSelector(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.- Specified by:
makeDimensionSelector
in interfaceVirtualColumn
-
makeColumnValueSelector
@Nullable public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)
Description copied from interface:VirtualColumn
Returns similarColumnValueSelector
object as returned byVirtualColumn.makeColumnValueSelector(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.- Specified by:
makeColumnValueSelector
in interfaceVirtualColumn
-
canVectorize
public boolean canVectorize(ColumnInspector inspector)
- Specified by:
canVectorize
in interfaceVirtualColumn
-
makeSingleValueVectorDimensionSelector
@Nullable public SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumn
Returns similarSingleValueDimensionVectorSelector
object as returned byVirtualColumn.makeSingleValueVectorDimensionSelector(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.- Specified by:
makeSingleValueVectorDimensionSelector
in interfaceVirtualColumn
-
makeVectorObjectSelector
@Nullable public VectorObjectSelector makeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumn
Returns similarVectorObjectSelector
object as returned byVirtualColumn.makeVectorObjectSelector(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.- Specified by:
makeVectorObjectSelector
in interfaceVirtualColumn
-
makeVectorValueSelector
@Nullable public VectorValueSelector makeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumn
Returns similarVectorValueSelector
object as returned byVirtualColumn.makeVectorValueSelector(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.- Specified by:
makeVectorValueSelector
in interfaceVirtualColumn
-
getIndexSupplier
@Nullable public ColumnIndexSupplier getIndexSupplier(String columnName, ColumnSelector selector)
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
-
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
-
-