Package org.apache.druid.math.expr
Class Parser
- java.lang.Object
-
- org.apache.druid.math.expr.Parser
-
public class Parser extends Object
-
-
Constructor Summary
Constructors Constructor Description Parser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Expr
applyUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply)
static Expr
flatten(Expr expr)
static Expr
foldUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply, String accumulatorId)
static ApplyFunction
getApplyFunction(String name)
static Function
getFunction(String name)
GetFunction
byNamedFunction.name()
static com.google.common.base.Supplier<Expr>
lazyParse(String in, ExprMacroTable macroTable)
Create a memoized lazy supplier to parse a string into a flattenedExpr
.static Expr
parse(String in, ExprMacroTable macroTable)
Parse a string into a flattenedExpr
.static Expr
parse(String in, ExprMacroTable macroTable, boolean withFlatten)
static void
validateExpr(Expr expression, Expr.BindingAnalysis bindingAnalysis)
Validate that an expression uses input bindings in a type consistent manner.
-
-
-
Method Detail
-
getFunction
public static Function getFunction(String name)
GetFunction
byNamedFunction.name()
-
getApplyFunction
public static ApplyFunction getApplyFunction(String name)
-
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
public static Expr parse(String in, ExprMacroTable macroTable)
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
public static Expr parse(String in, ExprMacroTable macroTable, boolean withFlatten)
-
applyUnappliedBindings
public static Expr applyUnappliedBindings(Expr expr, Expr.BindingAnalysis bindingAnalysis, List<String> bindingsToApply)
Applies a transformation to anExpr
given a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExpr
tree and lifting array variables into theLambdaExpr
ofApplyFunctionExpr
and transforming the arguments ofFunctionExpr
as 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 anExpr
given a list of known (or uknown) multi-value input columns that are used in a scalar manner, walking theExpr
tree and lifting array variables into theLambdaExpr
ofApplyFunctionExpr
and transforming the arguments ofFunctionExpr
as 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
public static void validateExpr(Expr expression, Expr.BindingAnalysis bindingAnalysis)
Validate that an expression uses input bindings in a type consistent manner.
-
-