Package org.apache.druid.math.expr
Class Expr.BindingAnalysis
java.lang.Object
org.apache.druid.math.expr.Expr.BindingAnalysis
- Enclosing interface:
Expr
Information about the context in which
IdentifierExpr are used in a greater Expr, 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.
This type is primarily used at query time when creating expression column selectors to decide if an expression
can properly deal with a multi-valued column input, and also to determine if certain optimizations can be taken.
Current implementations of Expr.analyzeInputs() provide context about Function and
ApplyFunction arguments which are direct children IdentifierExpr as scalar or array typed.
This is defined by Function.getScalarInputs(List), Function.getArrayInputs(List) and
ApplyFunction.getArrayInputs(List). Identifiers that are nested inside of argument expressions which
are other expression types will not be considered to belong directly to that function, and so are classified by the
context their children are using them as instead.
This means in rare cases and mostly for "questionable" expressions which we still allow to function 'correctly',
these lists might not be fully reliable without a complete type inference system in place. Due to this shortcoming,
boolean values hasInputArrays() and isOutputArray() are provided to
allow functions to explicitly declare that they utilize array typed values, used when determining if some types of
optimizations can be applied when constructing the expression column value selector.- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Expr.BindingAnalysiscollect(Collection<Expr.BindingAnalysis> others) Create an instance by combining a collection of other instances.static Expr.BindingAnalysiscollectExprs(Collection<Expr> exprs) Create an instance by combining a collection of analyses fromExpr.analyzeInputs().Set ofIdentifierExpr.bindingwhich are used as array inputs to operators, functions, and apply functions.Set<org.apache.druid.math.expr.IdentifierExpr> Total set of 'free' inputs of anExpr, that are not supplied by aLambdaExprbindingGet the set of required column inputs to evaluate an expression (IdentifierExpr.binding)Get the list of required column inputs to evaluate an expression (IdentifierExpr.binding)booleanReturns true if any expression in the expression tree has any array inputs.booleanReturns true if any expression in this expression tree produces array outputs as reported byFunction.hasArrayOutput()orApplyFunction.hasArrayOutput(LambdaExpr)withArrayArguments(Set<Expr> arrayArguments) Add set of arguments asarrayVariablesthat are *directly*IdentifierExpr, else they are ignored.withArrayInputs(boolean hasArrays) Copy, setting if an expression has array inputswithArrayOutput(boolean isOutputArray) Copy, setting if an expression produces an array outputwithScalarArguments(Set<Expr> scalarArguments) Add set of arguments asscalarVariablesthat are *directly*IdentifierExpr, else they are ignored.
-
Field Details
-
EMTPY
-
-
Constructor Details
-
BindingAnalysis
public BindingAnalysis()
-
-
Method Details
-
collect
Create an instance by combining a collection of other instances. -
collectExprs
Create an instance by combining a collection of analyses fromExpr.analyzeInputs(). -
getRequiredBindingsList
Get the list of required column inputs to evaluate an expression (IdentifierExpr.binding) -
getRequiredBindings
Get the set of required column inputs to evaluate an expression (IdentifierExpr.binding) -
getArrayBindings
Set ofIdentifierExpr.bindingwhich are used as array inputs to operators, functions, and apply functions. -
getFreeVariables
Total set of 'free' inputs of anExpr, that are not supplied by aLambdaExprbinding -
hasInputArrays
public boolean hasInputArrays()Returns true if any expression in the expression tree has any array inputs. Note that in some cases, this can be true andgetArrayBindings()orgetArrayVariables()can be empty. This is because these collections contain identifiers/bindings which were classified as either scalar or array inputs based on the context of their usage byExpr.analyzeInputs(), where as this value andisOutputArray()are set based on information reported byFunction.hasArrayInputs(),Function.hasArrayOutput(), andApplyFunction.hasArrayOutput(LambdaExpr), without regards to identifiers or anything else. -
isOutputArray
public boolean isOutputArray()Returns true if any expression in this expression tree produces array outputs as reported byFunction.hasArrayOutput()orApplyFunction.hasArrayOutput(LambdaExpr) -
withScalarArguments
Add set of arguments asscalarVariablesthat are *directly*IdentifierExpr, else they are ignored. -
withArrayArguments
Add set of arguments asarrayVariablesthat are *directly*IdentifierExpr, else they are ignored. -
withArrayInputs
Copy, setting if an expression has array inputs -
withArrayOutput
Copy, setting if an expression produces an array output
-