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 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 Details

  • Constructor Details

    • BindingAnalysis

      public BindingAnalysis()
  • Method Details

    • collect

      public static Expr.BindingAnalysis collect(Collection<Expr.BindingAnalysis> others)
      Create an instance by combining a collection of other instances.
    • collectExprs

      public static Expr.BindingAnalysis collectExprs(Collection<Expr> exprs)
      Create an instance by combining a collection of analyses from Expr.analyzeInputs().
    • 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 of IdentifierExpr.binding which 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 an Expr, that are not supplied by a LambdaExpr binding
    • 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 and getArrayBindings() or getArrayVariables() 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 by Expr.analyzeInputs(), where as this value and isOutputArray() are set based on information reported by Function.hasArrayInputs(), Function.hasArrayOutput(), and ApplyFunction.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 by Function.hasArrayOutput() or ApplyFunction.hasArrayOutput(LambdaExpr)
    • withScalarArguments

      public Expr.BindingAnalysis withScalarArguments(Set<Expr> scalarArguments)
      Add set of arguments as scalarVariables that are *directly* IdentifierExpr, else they are ignored.
    • withArrayArguments

      public Expr.BindingAnalysis withArrayArguments(Set<Expr> arrayArguments)
      Add set of arguments as arrayVariables that 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