Package org.apache.druid.math.expr
Class Expr.BindingAnalysis
- java.lang.Object
-
- org.apache.druid.math.expr.Expr.BindingAnalysis
-
- Enclosing interface:
- Expr
public static class Expr.BindingAnalysis extends Object
Information 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. 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 ofExpr.analyzeInputs()provide context aboutFunctionandApplyFunctionarguments which are direct childrenIdentifierExpras scalar or array typed. This is defined byFunction.getScalarInputs(List),Function.getArrayInputs(List)andApplyFunction.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 valueshasInputArrays()andisOutputArray()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:
Function.getScalarInputs(java.util.List<org.apache.druid.math.expr.Expr>),Function.getArrayInputs(java.util.List<org.apache.druid.math.expr.Expr>),ApplyFunction.getArrayInputs(java.util.List<org.apache.druid.math.expr.Expr>),Parser.applyUnappliedBindings(org.apache.druid.math.expr.Expr, org.apache.druid.math.expr.Expr.BindingAnalysis, java.util.List<java.lang.String>),Parser.applyUnapplied(org.apache.druid.math.expr.Expr, java.util.List<java.lang.String>),Parser.liftApplyLambda(org.apache.druid.math.expr.ApplyFunctionExpr, java.util.List<java.lang.String>),ExpressionSelectors.makeDimensionSelector(org.apache.druid.segment.ColumnSelectorFactory, org.apache.druid.math.expr.Expr, org.apache.druid.query.extraction.ExtractionFn),ExpressionSelectors.makeColumnValueSelector(org.apache.druid.segment.ColumnSelectorFactory, org.apache.druid.math.expr.Expr)
-
-
Field Summary
Fields Modifier and Type Field Description static Expr.BindingAnalysisEMTPY
-
Constructor Summary
Constructors Constructor Description BindingAnalysis()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>getArrayBindings()Set ofIdentifierExpr.bindingwhich are used as array inputs to operators, functions, and apply functions.Set<org.apache.druid.math.expr.IdentifierExpr>getFreeVariables()Total set of 'free' inputs of anExpr, that are not supplied by aLambdaExprbindingSet<String>getRequiredBindings()Get the set of required column inputs to evaluate an expression (IdentifierExpr.binding)List<String>getRequiredBindingsList()Get the list of required column inputs to evaluate an expression (IdentifierExpr.binding)booleanhasInputArrays()Returns true if any expression in the expression tree has any array inputs.booleanisOutputArray()Returns true if any expression in this expression tree produces array outputs as reported byFunction.hasArrayOutput()orApplyFunction.hasArrayOutput(LambdaExpr)Expr.BindingAnalysiswith(Expr other)Combine withExpr.BindingAnalysisfromExpr.analyzeInputs()Expr.BindingAnalysiswith(Expr.BindingAnalysis other)Combine (union) anotherExpr.BindingAnalysisExpr.BindingAnalysiswithArrayArguments(Set<Expr> arrayArguments)Add set of arguments asarrayVariablesthat are *directly*IdentifierExpr, else they are ignored.Expr.BindingAnalysiswithArrayInputs(boolean hasArrays)Copy, setting if an expression has array inputsExpr.BindingAnalysiswithArrayOutput(boolean isOutputArray)Copy, setting if an expression produces an array outputExpr.BindingAnalysiswithScalarArguments(Set<Expr> scalarArguments)Add set of arguments asscalarVariablesthat are *directly*IdentifierExpr, else they are ignored.
-
-
-
Field Detail
-
EMTPY
public static final Expr.BindingAnalysis EMTPY
-
-
Method Detail
-
getRequiredBindingsList
public List<String> getRequiredBindingsList()
Get the list of required column inputs to evaluate an expression (IdentifierExpr.binding)
-
getRequiredBindings
public Set<String> getRequiredBindings()
Get the set of required column inputs to evaluate an expression (IdentifierExpr.binding)
-
getArrayBindings
public Set<String> getArrayBindings()
Set ofIdentifierExpr.bindingwhich are used as array inputs to operators, functions, and apply functions.
-
getFreeVariables
public Set<org.apache.druid.math.expr.IdentifierExpr> 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)
-
with
public Expr.BindingAnalysis with(Expr other)
Combine withExpr.BindingAnalysisfromExpr.analyzeInputs()
-
with
public Expr.BindingAnalysis with(Expr.BindingAnalysis other)
Combine (union) anotherExpr.BindingAnalysis
-
withScalarArguments
public Expr.BindingAnalysis withScalarArguments(Set<Expr> scalarArguments)
Add set of arguments asscalarVariablesthat are *directly*IdentifierExpr, else they are ignored.
-
withArrayArguments
public Expr.BindingAnalysis withArrayArguments(Set<Expr> arrayArguments)
Add set of arguments asarrayVariablesthat are *directly*IdentifierExpr, else they are ignored.
-
withArrayInputs
public Expr.BindingAnalysis withArrayInputs(boolean hasArrays)
Copy, setting if an expression has array inputs
-
withArrayOutput
public Expr.BindingAnalysis withArrayOutput(boolean isOutputArray)
Copy, setting if an expression produces an array output
-
-