Package org.apache.druid.segment.virtual
Class ExpressionSelectors
java.lang.Object
org.apache.druid.segment.virtual.ExpressionSelectors
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanMapOverDictionary(Expr.BindingAnalysis bindingAnalysis, ColumnCapabilities columnCapabilities) Returns whether an expression can be applied to unique values of a particular column (like those in a dictionary) rather than being applied to each row individually.static ColumnValueSelector<?>castColumnValueSelector(RowIdSupplier rowIdSupplier, ColumnValueSelector<?> delegate, ColumnType delegateType, ColumnType castToType) Wrap the output ofBaseObjectColumnValueSelector.getObject()inExprEval.ofType(ExpressionType, Object)using the supplied delegate type and cast usingExprEval.castTo(org.apache.druid.math.expr.ExpressionType)to convert to the target type.static ObjectCoercesExprEvalvalue back to aColumnType.STRINGselector friendly value, converting into: - the expression value if the value is not an array - the single array element if the value is an array with 1 element - a list with all of the array elements if the value is an array with more than 1 element This method is used bymakeStringColumnValueSelector(ColumnSelectorFactory, Expr), which is used exclusively for makingColumnValueSelectorwhen anExpressionVirtualColumnhas STRING output type, and byExpressionTransformwhich should be reconsidered if we ever want to add support for ingestion transforms producingValueType.ARRAYtyped outputs.static Expr.ObjectBindingcreateBindings(ColumnSelectorFactory columnSelectorFactory, ExpressionPlan plan) CreateExpr.ObjectBindinggiven aColumnSelectorFactoryandExpressionPlanwhich provides the set of identifiers which need a binding (list of required columns), and context of whether or not they are used as array or scalar inputsstatic ColumnValueSelectormakeColumnValueSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression) Makes a ColumnValueSelector whose getObject method returns an Object that is the value computed by anExprEval.static DimensionSelectormakeDimensionSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression, ExtractionFn extractionFn) Makes a single or multi-valueDimensionSelectorwrapper around aColumnValueSelectorcreated bymakeExprEvalSelector(ColumnSelectorFactory, Expr)as appropriatestatic ColumnValueSelector<ExprEval>makeExprEvalSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression) Makes a ColumnValueSelector whose getObject method returns anExprEval.static <T> com.google.common.base.Supplier<T>makeNullableNumericSupplier(ColumnValueSelector selector, com.google.common.base.Supplier<T> supplier) Wraps aColumnValueSelectorand uses it to supply numeric values in a null-aware way.static ColumnValueSelectormakeStringColumnValueSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression)
-
Method Details
-
makeColumnValueSelector
public static ColumnValueSelector makeColumnValueSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression) Makes a ColumnValueSelector whose getObject method returns an Object that is the value computed by anExprEval. -
makeStringColumnValueSelector
public static ColumnValueSelector makeStringColumnValueSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression) -
castColumnValueSelector
public static ColumnValueSelector<?> castColumnValueSelector(RowIdSupplier rowIdSupplier, ColumnValueSelector<?> delegate, @Nullable ColumnType delegateType, ColumnType castToType) Wrap the output ofBaseObjectColumnValueSelector.getObject()inExprEval.ofType(ExpressionType, Object)using the supplied delegate type and cast usingExprEval.castTo(org.apache.druid.math.expr.ExpressionType)to convert to the target type. If the delegate selector type is null,ExprEval.ofType(org.apache.druid.math.expr.ExpressionType, java.lang.Object)falls back to usingExprEval.bestEffortOf(java.lang.Object), however the target type must be not null, or else this method will fail when attempting to convert to an expression type. -
makeExprEvalSelector
public static ColumnValueSelector<ExprEval> makeExprEvalSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression) Makes a ColumnValueSelector whose getObject method returns anExprEval. -
makeDimensionSelector
public static DimensionSelector makeDimensionSelector(ColumnSelectorFactory columnSelectorFactory, Expr expression, @Nullable ExtractionFn extractionFn) Makes a single or multi-valueDimensionSelectorwrapper around aColumnValueSelectorcreated bymakeExprEvalSelector(ColumnSelectorFactory, Expr)as appropriate -
canMapOverDictionary
public static boolean canMapOverDictionary(Expr.BindingAnalysis bindingAnalysis, @Nullable ColumnCapabilities columnCapabilities) Returns whether an expression can be applied to unique values of a particular column (like those in a dictionary) rather than being applied to each row individually. This function should only be called if you have already determined that an expression is over a single column, and that single column has a dictionary.- Parameters:
bindingAnalysis- result of callingExpr.analyzeInputs()on an expressioncolumnCapabilities-ColumnCapabilitiesfor the input binding
-
createBindings
public static Expr.ObjectBinding createBindings(ColumnSelectorFactory columnSelectorFactory, ExpressionPlan plan) CreateExpr.ObjectBindinggiven aColumnSelectorFactoryandExpressionPlanwhich provides the set of identifiers which need a binding (list of required columns), and context of whether or not they are used as array or scalar inputs -
makeNullableNumericSupplier
public static <T> com.google.common.base.Supplier<T> makeNullableNumericSupplier(ColumnValueSelector selector, com.google.common.base.Supplier<T> supplier) Wraps aColumnValueSelectorand uses it to supply numeric values in a null-aware way. -
coerceEvalToObjectOrList
CoercesExprEvalvalue back to aColumnType.STRINGselector friendly value, converting into: - the expression value if the value is not an array - the single array element if the value is an array with 1 element - a list with all of the array elements if the value is an array with more than 1 element This method is used bymakeStringColumnValueSelector(ColumnSelectorFactory, Expr), which is used exclusively for makingColumnValueSelectorwhen anExpressionVirtualColumnhas STRING output type, and byExpressionTransformwhich should be reconsidered if we ever want to add support for ingestion transforms producingValueType.ARRAYtyped outputs.
-