Package org.apache.druid.math.expr
Interface Expr
-
- All Superinterfaces:
Cacheable
- All Known Subinterfaces:
ExprMacroTable.ExprMacroFunctionExpr
- All Known Implementing Classes:
ExprMacroTable.BaseMacroFunctionExpr,ExprMacroTable.BaseScalarMacroFunctionExpr,TimestampExtractExprMacro.TimestampExtractDynamicExpr,TimestampExtractExprMacro.TimestampExtractExpr,TimestampFloorExprMacro.TimestampFloorDynamicExpr,TimestampFloorExprMacro.TimestampFloorExpr
@SubclassesMustOverrideEqualsAndHashCode public interface Expr extends Cacheable
Base interface of Druid expression language abstract syntax tree nodes. AllExprimplementations are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classExpr.BindingAnalysisInformation 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 interfaceExpr.InputBindingInspectorMechanism 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 interfaceExpr.ObjectBindingMechanism to supply values to backIdentifierExprduring expression evaluationstatic interfaceExpr.ShuttleMechanism to rewrite anExpr, implementing aExpr.Shuttleallows visiting all children of anExpr, and replacing them as desired.static interfaceExpr.VectorInputBindingMechanism to supply batches of input values to aExprVectorProcessorfor optimized processing.static interfaceExpr.VectorInputBindingInspectorExpr.InputBindingInspector+ vectorizations stuff forasVectorProcessor(org.apache.druid.math.expr.Expr.VectorInputBindingInspector)
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.JoinerARG_JOINERstatic StringNULL_LITERAL
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Expr.BindingAnalysisanalyzeInputs()default ColumnIndexSupplierasColumnIndexSupplier(ColumnIndexSelector columnIndexSelector, ColumnType outputType)default ExprasSingleThreaded(Expr.InputBindingInspector inspector)default <T> ExprVectorProcessor<T>asVectorProcessor(Expr.VectorInputBindingInspector inspector)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().ExprEvaleval(Expr.ObjectBinding bindings)default StringgetBindingIfIdentifier()Returns the string key to use to get a value fromExpr.ObjectBindingof anIdentifierExpr, else null.default byte[]getCacheKey()Get a byte array used as a cache key.default org.apache.druid.math.expr.IdentifierExprgetIdentifierExprIfIdentifierExpr()Returns anIdentifierExprif it is one, else nulldefault StringgetIdentifierIfIdentifier()Returns the string identifier of anIdentifierExpr, else null.default ObjectgetLiteralValue()Returns 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 booleanisIdentifier()default booleanisLiteral()Indicates expression is a constant whose literal value can be extracted bygetLiteralValue(), making evaluating with arguments and bindings unecessarydefault booleanisNullLiteral()static ExprsingleThreaded(Expr expr, Expr.InputBindingInspector inspector)Returns the single-threaded version of the given expression tree.Stringstringify()Convert theExprback into parseable string that when parsed withParser.parse(String, ExprMacroTable)will produce an equivalentExpr.Exprvisit(Expr.Shuttle shuttle)Programatically rewrite theExprtree with aExpr.Shuttle.
-
-
-
Field Detail
-
NULL_LITERAL
static final String NULL_LITERAL
- See Also:
- Constant Field Values
-
ARG_JOINER
static final com.google.common.base.Joiner ARG_JOINER
-
-
Method Detail
-
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
@Nullable default Object 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
@Nullable default String 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
@Nullable default String 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
ExprEval eval(Expr.ObjectBinding bindings)
-
stringify
String stringify()
Convert theExprback into parseable string that when parsed withParser.parse(String, ExprMacroTable)will produce an equivalentExpr.
-
visit
Expr visit(Expr.Shuttle shuttle)
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
@Nullable default ExpressionType getOutputType(Expr.InputBindingInspector inspector)
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
default boolean canVectorize(Expr.InputBindingInspector inspector)
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
default Expr asSingleThreaded(Expr.InputBindingInspector inspector)
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
default <T> ExprVectorProcessor<T> asVectorProcessor(Expr.VectorInputBindingInspector inspector)
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)
-
decorateCacheKeyBuilder
default void decorateCacheKeyBuilder(CacheKeyBuilder builder)
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:
- a cache key
-
singleThreaded
static Expr singleThreaded(Expr expr, Expr.InputBindingInspector inspector)
Returns the single-threaded version of the given expression tree. Nested expressions in the subtree are also optimized.
-
-