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 aNestedDataComplexColumnor any associated nested fields (NestedFieldDictionaryEncodedColumn) including using their indexes.This virtual column is used for the SQL operators JSON_VALUE (if
isProcessFromRaw()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 ofNestedPathPartin 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
getExpectedType()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 thegetExpectedType(), 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 classNestedFieldVirtualColumn.FieldDimensionSelectorstatic classNestedFieldVirtualColumn.RawFieldColumnSelectorProcess the "raw" data to extract values withNestedPathFinder.find(Object, List), wrapping the result inStructuredDatastatic classNestedFieldVirtualColumn.RawFieldLiteralColumnValueSelectorProcess the "raw" data to extract non-complex values.static classNestedFieldVirtualColumn.RawFieldVectorObjectSelectorProcess the "raw" data to extract vectors of values withNestedPathFinder.find(Object, List), wrapping the result inStructuredData-
Nested classes/interfaces inherited from interface org.apache.druid.segment.VirtualColumn
VirtualColumn.EquivalenceKey
-
-
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 booleancanVectorize(ColumnInspector inspector)ColumnCapabilitiescapabilities(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.ColumnCapabilitiescapabilities(ColumnInspector inspector, String columnName)Return theColumnCapabilitieswhich best describe the optimal selector to read from this virtual column.booleanequals(Object o)byte[]getCacheKey()Get a byte array used as a cache key.StringgetColumnName()VirtualColumn.EquivalenceKeygetEquivalanceKey()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.ColumnTypegetExpectedType()ColumnIndexSuppliergetIndexSupplier(String columnName, ColumnIndexSelector indexSelector)Get theColumnIndexSupplierfor the specified virtual column, with the assistance of aColumnIndexSelectorto allow reading things from segments.StringgetOutputName()Output name of this column.List<NestedPathPart>getPathParts()inthashCode()booleanisProcessFromRaw()ColumnValueSelector<?>makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)Build aColumnValueSelectorcorresponding to this virtual column.ColumnValueSelector<?>makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)Returns similarColumnValueSelectorobject as returned byVirtualColumn.makeColumnValueSelector(String, ColumnSelectorFactory)except this method has full access to the underlying column and can potentially provide a more efficient implementation.DimensionSelectormakeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)Build a selector corresponding to this virtual column.DimensionSelectormakeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)Returns similarDimensionSelectorobject as returned byVirtualColumn.makeDimensionSelector(DimensionSpec, ColumnSelectorFactory)except this method has full access to the underlying column and can potentially provide a more efficient implementation.SingleValueDimensionVectorSelectormakeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)Returns similarSingleValueDimensionVectorSelectorobject 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.VectorObjectSelectormakeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)Returns similarVectorObjectSelectorobject as returned byVirtualColumn.makeVectorObjectSelector(String, VectorColumnSelectorFactory)except this method has full access to the underlying column and can potentially provide a more efficient implementation.VectorValueSelectormakeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)Returns similarVectorValueSelectorobject 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.StringtoString()booleanusesDotNotation()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
makeGroupByVectorColumnSelector, 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:CacheableGet a byte array used as a cache key.- Specified by:
getCacheKeyin interfaceCacheable- Returns:
- a cache key
-
getOutputName
public String getOutputName()
Description copied from interface:VirtualColumnOutput name of this column.- Specified by:
getOutputNamein 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:VirtualColumnBuild 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:
makeDimensionSelectorin interfaceVirtualColumn
-
makeColumnValueSelector
public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory factory)
Description copied from interface:VirtualColumnBuild aColumnValueSelectorcorresponding 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:
makeColumnValueSelectorin interfaceVirtualColumn
-
makeDimensionSelector
@Nullable public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset)
Description copied from interface:VirtualColumnReturns similarDimensionSelectorobject 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:
makeDimensionSelectorin interfaceVirtualColumn
-
makeColumnValueSelector
@Nullable public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelector columnSelector, ReadableOffset offset)
Description copied from interface:VirtualColumnReturns similarColumnValueSelectorobject 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:
makeColumnValueSelectorin interfaceVirtualColumn
-
canVectorize
public boolean canVectorize(ColumnInspector inspector)
- Specified by:
canVectorizein interfaceVirtualColumn
-
makeSingleValueVectorDimensionSelector
@Nullable public SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumnReturns similarSingleValueDimensionVectorSelectorobject 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:
makeSingleValueVectorDimensionSelectorin interfaceVirtualColumn
-
makeVectorObjectSelector
@Nullable public VectorObjectSelector makeVectorObjectSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumnReturns similarVectorObjectSelectorobject 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:
makeVectorObjectSelectorin interfaceVirtualColumn
-
makeVectorValueSelector
@Nullable public VectorValueSelector makeVectorValueSelector(String columnName, ColumnSelector columnSelector, ReadableVectorOffset offset)
Description copied from interface:VirtualColumnReturns similarVectorValueSelectorobject 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:
makeVectorValueSelectorin interfaceVirtualColumn
-
getIndexSupplier
@Nullable public ColumnIndexSupplier getIndexSupplier(String columnName, ColumnIndexSelector indexSelector)
Description copied from interface:VirtualColumnGet theColumnIndexSupplierfor the specified virtual column, with the assistance of aColumnIndexSelectorto 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:
getIndexSupplierin interfaceVirtualColumn
-
capabilities
public ColumnCapabilities capabilities(String columnName)
Description copied from interface:VirtualColumnThis 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:
capabilitiesin 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:VirtualColumnReturn theColumnCapabilitieswhich best describe the optimal selector to read from this virtual column.The
ColumnInspector(most likely corresponding to an underlyingColumnSelectorFactoryof 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 theColumnInspectorto infer the output type of expressions based on the types of the inputs.- Specified by:
capabilitiesin 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:VirtualColumnReturns 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:
requiredColumnsin interfaceVirtualColumn- Returns:
- column names
-
usesDotNotation
public boolean usesDotNotation()
Description copied from interface:VirtualColumnIndicates 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:
usesDotNotationin interfaceVirtualColumn- Returns:
- whether to use dot notation
-
getEquivalanceKey
@Nullable public VirtualColumn.EquivalenceKey getEquivalanceKey()
Description copied from interface:VirtualColumnReturns 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.- Specified by:
getEquivalanceKeyin interfaceVirtualColumn- See Also:
VirtualColumns.findEquivalent(VirtualColumn)
-
-