Class Binder


  • public class Binder
    extends java.lang.Object
    Rewrites expressions by replacing unbound named references with references to fields in a struct schema.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Expression bind​(Types.StructType struct, Expression expr, boolean caseSensitive)
      Replaces all unbound/named references with bound references to fields in the given struct.
      static java.util.Set<java.lang.Integer> boundReferences​(Types.StructType struct, java.util.List<Expression> exprs, boolean caseSensitive)  
      static boolean isBound​(Expression expr)
      Returns whether an expression is bound.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • bind

        public static Expression bind​(Types.StructType struct,
                                      Expression expr,
                                      boolean caseSensitive)
        Replaces all unbound/named references with bound references to fields in the given struct.

        When a reference is resolved, any literal used in a predicate for that field is converted to the field's type using Literal.to(Type). If automatic conversion to that type isn't allowed, a validation exception is thrown.

        The result expression may be simplified when constructed. For example, isNull("a") is replaced with alwaysFalse() when "a" is resolved to a required field.

        The expression cannot contain references that are already bound, or an IllegalStateException will be thrown.

        Parameters:
        struct - The struct type to resolve references by name.
        expr - An expression to rewrite with bound references.
        caseSensitive - A boolean flag to control whether the bind should enforce case sensitivity.
        Returns:
        the expression rewritten with bound references
        Throws:
        ValidationException - if literals do not match bound references
        java.lang.IllegalStateException - if any references are already bound
      • boundReferences

        public static java.util.Set<java.lang.Integer> boundReferences​(Types.StructType struct,
                                                                       java.util.List<Expression> exprs,
                                                                       boolean caseSensitive)
      • isBound

        public static boolean isBound​(Expression expr)
        Returns whether an expression is bound.

        An expression is bound if all of its predicates are bound.

        Parameters:
        expr - an Expression
        Returns:
        true if the expression is bound
        Throws:
        java.lang.IllegalArgumentException - if the expression has both bound and unbound predicates.