Interface Expr
- All Superinterfaces:
Cacheable
- All Known Subinterfaces:
ExprMacroTable.ExprMacroFunctionExpr
- All Known Implementing Classes:
ExprMacroTable.BaseMacroFunctionExpr,ExprMacroTable.BaseScalarMacroFunctionExpr,LambdaExpr,TimestampExtractExprMacro.TimestampExtractDynamicExpr,TimestampExtractExprMacro.TimestampExtractExpr,TimestampFloorExprMacro.TimestampFloorDynamicExpr,TimestampFloorExprMacro.TimestampFloorExpr
Expr implementations are
immutable.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classInformation about the context in whichIdentifierExprare used in a greaterExpr, listing the 'free variables' (total set of required input columns or values) and distinguishing between which identifiers are used as scalar inputs and which are used as array inputs.static interfaceMechanism to supply input types for the bindings which will backIdentifierExpr, to use in the aid of inferring the output type of an expression withgetOutputType(org.apache.druid.math.expr.Expr.InputBindingInspector).static interfaceMechanism to supply values to backIdentifierExprduring expression evaluationstatic interfaceMechanism to rewrite anExpr, implementing aExpr.Shuttleallows visiting all children of anExpr, and replacing them as desired.static interfaceMechanism to supply batches of input values to aExprVectorProcessorfor optimized processing.static interfaceExpr.InputBindingInspector+ vectorizations stuff forasVectorProcessor(org.apache.druid.math.expr.Expr.VectorInputBindingInspector) -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault BitmapColumnIndexasBitmapColumnIndex(ColumnIndexSelector selector) Allows anExprto be computed into aBitmapColumnIndex.default ColumnIndexSupplierasColumnIndexSupplier(ColumnIndexSelector columnIndexSelector, ColumnType outputType) Allows anExprto provide anColumnIndexSuppliergiven access to the underlyingColumnIndexSupplierandColumnHolderof the base table.default ExprasSingleThreaded(Expr.InputBindingInspector inspector) default <T> ExprVectorProcessor<T> Builds a 'vectorized' expression processor, that can operate on batches of input values for use in vectorized query engines.default booleancanVectorize(Expr.InputBindingInspector inspector) Check if an expression can be 'vectorized', for a given set of inputs.default voiddecorateCacheKeyBuilder(CacheKeyBuilder builder) Decorates theCacheKeyBuilderfor the default implementation ofgetCacheKey().eval(Expr.ObjectBinding bindings) default StringReturns the string key to use to get a value fromExpr.ObjectBindingof anIdentifierExpr, else null.default byte[]Get a byte array used as a cache key.default org.apache.druid.math.expr.IdentifierExprReturns anIdentifierExprif it is one, else nulldefault StringReturns the string identifier of anIdentifierExpr, else null.default ObjectReturns the value of expr if expr is a literal, or throws an exception otherwise.default ExpressionTypegetOutputType(Expr.InputBindingInspector inspector) Given anExpr.InputBindingInspector, compute what the outputExpressionTypewill be for this expression.default booleandefault booleanIndicates expression is a constant whose literal value can be extracted bygetLiteralValue(), making evaluating with arguments and bindings unecessarydefault booleanstatic ExprsingleThreaded(Expr expr, Expr.InputBindingInspector inspector) Returns the single-threaded version of the given expression tree.Convert theExprback into parseable string that when parsed withParser.parse(String, ExprMacroTable)will produce an equivalentExpr.visit(Expr.Shuttle shuttle) Programatically rewrite theExprtree with aExpr.Shuttle.
-
Field Details
-
NULL_LITERAL
- See Also:
-
ARG_JOINER
static final com.google.common.base.Joiner ARG_JOINER
-
-
Method Details
-
isLiteral
default boolean isLiteral()Indicates expression is a constant whose literal value can be extracted bygetLiteralValue(), making evaluating with arguments and bindings unecessary -
isNullLiteral
default boolean isNullLiteral() -
isIdentifier
default boolean isIdentifier() -
getLiteralValue
Returns the value of expr if expr is a literal, or throws an exception otherwise.- Returns:
ConstantExpr's literal value- Throws:
IllegalStateException- if expr is not a literal
-
getIdentifierExprIfIdentifierExpr
@Nullable default org.apache.druid.math.expr.IdentifierExpr getIdentifierExprIfIdentifierExpr()Returns anIdentifierExprif it is one, else null -
getIdentifierIfIdentifier
Returns the string identifier of anIdentifierExpr, else null. Use this method to analyze anExprtree when trying to distinguish between differentIdentifierExprwith the sameIdentifierExpr.binding. Do NOT use this method to analyze the input binding (e.g. backing column name), usegetBindingIfIdentifier()instead. -
getBindingIfIdentifier
Returns the string key to use to get a value fromExpr.ObjectBindingof anIdentifierExpr, else null. Use this method to analyze the inputs required to anExprtree (e.g. backing column name). -
eval
-
stringify
String stringify()Convert theExprback into parseable string that when parsed withParser.parse(String, ExprMacroTable)will produce an equivalentExpr. -
visit
Programatically rewrite theExprtree with aExpr.Shuttle. EachExpris responsible for ensuring theExpr.Shuttlecan visit all of itsExprchildren, as well as updating its childrenExprwith the results from theExpr.Shuttle, before finally visiting an updated form of itself. When this Expr is the result ofExprMacroTable.ExprMacro.apply(java.util.List<org.apache.druid.math.expr.Expr>), all of the original arguments to the macro must be visited, including arguments that may have been "baked in" to this Expr. -
analyzeInputs
Expr.BindingAnalysis analyzeInputs() -
getOutputType
Given anExpr.InputBindingInspector, compute what the outputExpressionTypewill be for this expression. In the vectorized expression engine, ifcanVectorize(InputBindingInspector)returns true, a return value of null MUST ONLY indicate that the expression has all null inputs (non-existent columns) or null constants for the entire expression. Otherwise, all vectorizable expressions must produce an output type to correctly operate with the vectorized engine. Outside the context of vectorized expressions, a return value of null can also indicate that the given type information was not enough to resolve the output type, so the expression must be evaluated using defaulteval(org.apache.druid.math.expr.Expr.ObjectBinding)handling where types are only known after evaluation, throughExprEval.type(), such as transform expressions at ingestion time -
canVectorize
Check if an expression can be 'vectorized', for a given set of inputs. If this method returns true,asVectorProcessor(org.apache.druid.math.expr.Expr.VectorInputBindingInspector)is expected to produce aExprVectorProcessorwhich can evaluate values in batches to use with vectorized query engines.- Parameters:
inspector-
-
asSingleThreaded
Possibly convert theExprinto an optimized, possibly not thread-safeExpr. Does not convert childExpr. Most callers should usesingleThreaded(Expr, InputBindingInspector)to convert an entire tree, which delegates to this method to translate individual nodes. -
asVectorProcessor
Builds a 'vectorized' expression processor, that can operate on batches of input values for use in vectorized query engines.- Parameters:
inspector-
-
asColumnIndexSupplier
@Nullable default ColumnIndexSupplier asColumnIndexSupplier(ColumnIndexSelector columnIndexSelector, @Nullable ColumnType outputType) Allows anExprto provide anColumnIndexSuppliergiven access to the underlyingColumnIndexSupplierandColumnHolderof the base table.The default implementation provides an index supplier if there is a single input column, and that column can provide
DictionaryEncodedValueIndex, then the expression can provideDruidPredicateIndexesthat apply a predicate.This method has the same null contract as
ColumnIndexSelector.getIndexSupplier(String), and should only return null if the column is completely null and theExprproduces a null constant in the missing column case. Otherwise, if no index supplier can be provided, this method should returnNoIndexesColumnIndexSupplier.getInstance(). -
asBitmapColumnIndex
Allows anExprto be computed into aBitmapColumnIndex. The suppliedColumnIndexSelectorprovides access to underlyingColumnIndexSupplierand evenColumnHolder. Coupled withasColumnIndexSupplier(ColumnIndexSelector, ColumnType), which allowsExprto provide indexes of their own, it allows for a system of composing additional indexes on top of any base column structures.For example,
BinEqExprwhere one argument is a constant, can use theValueIndexesif present of the non-constant arguments' index supplier.If this method returns null, it means that an index could not be produced for this
Expr. -
decorateCacheKeyBuilder
Decorates theCacheKeyBuilderfor the default implementation ofgetCacheKey(). The default cache key implementation includes the output ofstringify()and then uses aExpr.Shuttleto call this method on all children. The stringified representation is sufficient for most expressions, but for any which rely on external state that might change, this method allows the cache key to change when the state does, even if the expression itself is otherwise the same. -
getCacheKey
default 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.
-
singleThreaded
Returns the single-threaded version of the given expression tree. Nested expressions in the subtree are also optimized.
-