Package org.apache.druid.math.expr
Class Parser
java.lang.Object
org.apache.druid.math.expr.Parser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExprapplyUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply) Applies a transformation to anExprgiven a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExprtree and lifting array variables into theLambdaExprofApplyFunctionExprand transforming the arguments ofFunctionExpras necessary.static ExprCreate aStringExprfor a string constantstatic Exprstatic ExprfoldUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply, String accumulatorId) Applies a transformation to anExprgiven a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExprtree and lifting array variables into theLambdaExprofApplyFunctionExprand transforming the arguments ofFunctionExpras necessary.static ApplyFunctiongetApplyFunction(String name) static FunctiongetFunction(String name) GetFunctionbyNamedFunction.name()static Expridentifier(String identifier) Create anIdentifierExprfor some identifierstatic com.google.common.base.Supplier<Expr>lazyParse(String in, ExprMacroTable macroTable) Create a memoized lazy supplier to parse a string into a flattenedExpr.static Exprparse(String in, ExprMacroTable macroTable) Parse a string into a flattenedExpr.static Exprparse(String in, ExprMacroTable macroTable, boolean withFlatten) static voidvalidateExpr(Expr expression, Expr.BindingAnalysis bindingAnalysis) Validate that an expression uses input bindings in a type consistent manner.
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
getFunction
GetFunctionbyNamedFunction.name() -
getApplyFunction
-
lazyParse
public static com.google.common.base.Supplier<Expr> lazyParse(@Nullable String in, ExprMacroTable macroTable) Create a memoized lazy supplier to parse a string into a flattenedExpr. There is some overhead to this, and these objects are all immutable, so this assists in the goal of re-using instead of re-creating whenever possible. Lazy form ofparse(String, ExprMacroTable)- Parameters:
in- expression to parsemacroTable- additional extensions to expression language
-
parse
Parse a string into a flattenedExpr. There is some overhead to this, and these objects are all immutable, so re-use instead of re-creating whenever possible.- Parameters:
in- expression to parsemacroTable- additional extensions to expression language
-
parse
-
identifier
Create anIdentifierExprfor some identifier -
constant
Create aStringExprfor a string constant -
flatten
-
applyUnappliedBindings
public static Expr applyUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply) Applies a transformation to anExprgiven a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExprtree and lifting array variables into theLambdaExprofApplyFunctionExprand transforming the arguments ofFunctionExpras necessary. This function applies a transformation for "map" style uses, such as column selectors, where the supplied expression will be transformed to return an array of results instead of the scalar result (or appropriately rewritten into existing apply expressions to produce correct results when referenced from a scalar context). This function andfoldUnappliedBindings(Expr, Expr.BindingAnalysis, List, String)exist to handle "multi-valued" string dimensions, which exist in a superposition of both single and multi-valued during realtime ingestion, until they are written to a segment and become locked into either single or multi-valued. This also means that multi-valued-ness can vary for a column from segment to segment, so this family of transformation functions exist so that multi-valued strings can be expressed in either and array or scalar context, which is important because the writer of the query might not actually know if the column is definitively always single or multi-valued (and it might in fact not be). -
foldUnappliedBindings
public static Expr foldUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply, String accumulatorId) Applies a transformation to anExprgiven a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExprtree and lifting array variables into theLambdaExprofApplyFunctionExprand transforming the arguments ofFunctionExpras necessary. This function applies a transformation for "fold" style uses, such as aggregators, where the supplied expression will be transformed to accumulate the result of applying the expression to each value of the unapplied input (or appropriately rewritten into existing apply expressions to produce correct results when referenced from a scalar context). This rewriting assumes that there exists some accumulator variable, which is re-used as the accumulator for this fold rewrite, so that evaluating each expression can be accumulated into the larger external fold operation that an aggregator might be performing. This function andapplyUnappliedBindings(Expr, Expr.BindingAnalysis, List)exist to handle "multi-valued" string dimensions, which exist in a superposition of both single and multi-valued during realtime ingestion, until they are written to a segment and become locked into either single or multi-valued. This also means that multi-valued-ness can vary for a column from segment to segment, so this family of transformation functions exist so that multi-valued strings can be expressed in either and array or scalar context, which is important because the writer of the query might not actually know if the column is definitively always single or multi-valued (and it might in fact not be). -
validateExpr
Validate that an expression uses input bindings in a type consistent manner.
-