Class NestedFieldVirtualColumn
- All Implemented Interfaces:
Cacheable,VirtualColumn
NestedDataComplexColumn or 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 of NestedPathPart 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
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 the getExpectedType(), 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 ClassesModifier and TypeClassDescriptionstatic final classCreate aDimensionSelectorfor a nested field on top of aColumnValueSelectorstatic final classProcess the "raw" data to extract vectors of values withNestedPathFinder.find(Object, List), returning a value matching an expected type.Nested classes/interfaces inherited from interface org.apache.druid.segment.VirtualColumn
VirtualColumn.EquivalenceKey -
Constructor Summary
ConstructorsConstructorDescriptionNestedFieldVirtualColumn(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
Modifier and TypeMethodDescriptionbooleancanVectorize(ColumnInspector inspector) 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.capabilities(ColumnInspector inspector, String columnName) Return theColumnCapabilitieswhich best describe the optimal selector to read from this virtual column.booleanbyte[]Get a byte array used as a cache key.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.getIndexSupplier(String columnName, ColumnIndexSelector indexSelector) Get theColumnIndexSupplierof the specified virtual column, with the assistance of aColumnSelectorto allow reading things from segments.Output name of this column.inthashCode()booleanmakeColumnValueSelector(String columnName, ColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableOffset offset) Builds a selector corresponding to this virtual column.makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableOffset offset) Build a selector corresponding to this virtual column.makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Build a selector corresponding to this virtual column.makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Build a selector corresponding to this virtual column.makeVectorValueSelector(String columnName, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Build a selector corresponding to this virtual column.Returns a list of columns that this virtual column will access.rewriteRequiredColumns(Map<String, String> columnRewrites) Return a copy of this virtual column that is identical to this virtual column except that it operates on different columns, based on a renaming map where the key is the column to be renamed and the value is the new column.booleanReturns true if the virtual column supportsVirtualColumn.rewriteRequiredColumns(Map)toString()booleanIndicates that this virtual column can be referenced with dot notation.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.druid.segment.VirtualColumn
makeColumnValueSelector, makeColumnValueSelector, makeDimensionSelector, makeDimensionSelector, makeGroupByVectorColumnSelector, makeMultiValueVectorDimensionSelector, makeMultiValueVectorDimensionSelector, makeMultiValueVectorDimensionSelector, makeSingleValueVectorDimensionSelector, makeSingleValueVectorDimensionSelector, makeVectorObjectSelector, makeVectorObjectSelector, makeVectorValueSelector, makeVectorValueSelector, toSelectableColumn
-
Constructor Details
-
NestedFieldVirtualColumn
public NestedFieldVirtualColumn(String columnName, String outputName, @Nullable ColumnType expectedType, @Nullable List<NestedPathPart> parts, @Nullable Boolean processFromRaw, @Nullable String path, @Nullable Boolean useJqSyntax) -
NestedFieldVirtualColumn
-
NestedFieldVirtualColumn
public NestedFieldVirtualColumn(String columnName, String path, String outputName, @Nullable ColumnType expectedType)
-
-
Method Details
-
getCacheKey
@Nullable public byte[] getCacheKey()Description copied from interface:CacheableGet a byte array used as a cache key.- Specified by:
getCacheKeyin interfaceCacheable- Returns:
- bytes to be used as cache key - or null if this object should not be cached.
-
getOutputName
Description copied from interface:VirtualColumnOutput name of this column.- Specified by:
getOutputNamein interfaceVirtualColumn- Returns:
- name
-
getColumnName
-
getPathParts
-
getExpectedType
-
isProcessFromRaw
public boolean isProcessFromRaw() -
makeDimensionSelector
public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory selectorFactory, @Nullable ColumnSelector columnSelector, @Nullable ReadableOffset offset) Description copied from interface:VirtualColumnBuild a selector corresponding to this virtual column. The virtual column is expected to apply any necessaryDimensionSpec.decorate(DimensionSelector)orDimensionSpec.getExtractionFn()from the dimensionSpec.- Specified by:
makeDimensionSelectorin interfaceVirtualColumn- Parameters:
dimensionSpec- spec the column was referenced with. Also provides the name that the virtual column was referenced with, which is useful if this column uses dot notation.selectorFactory- object for fetching underlying selectors.columnSelector- object for fetching underlying columns, if available. Generally only available for regular segments.offset- offset to use with underlying columns. Available only if columnSelector is available.
-
makeColumnValueSelector
public ColumnValueSelector<?> makeColumnValueSelector(String columnName, ColumnSelectorFactory selectorFactory, @Nullable ColumnSelector columnSelector, @Nullable ReadableOffset offset) Description copied from interface:VirtualColumnBuilds a selector corresponding to this virtual column.- Specified by:
makeColumnValueSelectorin interfaceVirtualColumn- Parameters:
columnName- name the column was referenced with, which is useful if this column uses dot notation.selectorFactory- object for fetching underlying selectors.columnSelector- object for fetching underlying columns, if available. Generally only available for regular segments.offset- offset to use with underlying columns. Available only if columnSelector is available.
-
canVectorize
- Specified by:
canVectorizein interfaceVirtualColumn
-
makeSingleValueVectorDimensionSelector
public SingleValueDimensionVectorSelector makeSingleValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Description copied from interface:VirtualColumnBuild a selector corresponding to this virtual column. The virtual column is expected to apply any necessaryDimensionSpec.decorate(DimensionSelector)orDimensionSpec.getExtractionFn()from the dimensionSpec.- Specified by:
makeSingleValueVectorDimensionSelectorin interfaceVirtualColumn- Parameters:
dimensionSpec- spec the column was referenced with. Also provides the name that the virtual column was referenced with, which is useful if this column uses dot notation.selectorFactory- object for fetching underlying selectors.columnSelector- object for fetching underlying columns.offset- offset to use with underlying columns.
-
makeVectorObjectSelector
public VectorObjectSelector makeVectorObjectSelector(String columnName, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Description copied from interface:VirtualColumnBuild a selector corresponding to this virtual column. The virtual column is expected to apply any necessaryDimensionSpec.decorate(DimensionSelector)orDimensionSpec.getExtractionFn()from the dimensionSpec.- Specified by:
makeVectorObjectSelectorin interfaceVirtualColumn- Parameters:
columnName- name the column was referenced with, which is useful if this column uses dot notation.selectorFactory- object for fetching underlying selectors.columnSelector- object for fetching underlying columns, if available. Generally only available for regular segments.offset- offset to use with underlying columns. Available only if columnSelector is available.
-
makeVectorValueSelector
public VectorValueSelector makeVectorValueSelector(String columnName, VectorColumnSelectorFactory selectorFactory, ColumnSelector columnSelector, ReadableVectorOffset offset) Description copied from interface:VirtualColumnBuild a selector corresponding to this virtual column. The virtual column is expected to apply any necessaryDimensionSpec.decorate(DimensionSelector)orDimensionSpec.getExtractionFn()from the dimensionSpec.- Specified by:
makeVectorValueSelectorin interfaceVirtualColumn- Parameters:
columnName- name the column was referenced with, which is useful if this column uses dot notation.selectorFactory- object for fetching underlying selectors.columnSelector- object for fetching underlying columns.offset- offset to use with underlying columns.
-
getIndexSupplier
@Nullable public ColumnIndexSupplier getIndexSupplier(String columnName, ColumnIndexSelector indexSelector) Description copied from interface:VirtualColumnGet theColumnIndexSupplierof the specified virtual column, with the assistance of aColumnSelectorto allow reading things from segments. Returns null if the virtual column wants to act like a missing column. ReturnsNoIndexesColumnIndexSupplier.getInstance()if the virtual column does not support indexes and wants cursor-based filtering.- Specified by:
getIndexSupplierin interfaceVirtualColumn
-
capabilities
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
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, or null if the column should be treated as if it doesn't exist.
-
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
-
supportsRequiredRewrite
public boolean supportsRequiredRewrite()Description copied from interface:VirtualColumnReturns true if the virtual column supportsVirtualColumn.rewriteRequiredColumns(Map)- Specified by:
supportsRequiredRewritein interfaceVirtualColumn
-
rewriteRequiredColumns
Description copied from interface:VirtualColumnReturn a copy of this virtual column that is identical to this virtual column except that it operates on different columns, based on a renaming map where the key is the column to be renamed and the value is the new column. Callers should checkVirtualColumn.supportsRequiredRewrite()first to ensure that this method is supported.- Specified by:
rewriteRequiredColumnsin interfaceVirtualColumn- Parameters:
columnRewrites- Column rewrite map- Returns:
- Copy of this virtual column that operates on new columns based on the rewrite map
-
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
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:
-
equals
-
hashCode
public int hashCode() -
toString
-