Class ExpressionUtil


  • public class ExpressionUtil
    extends java.lang.Object
    Expression utility methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String describe​(Term term)  
      static boolean equivalent​(Expression left, Expression right, Types.StructType struct, boolean caseSensitive)
      Returns whether two unbound expressions will accept the same inputs.
      static Expression extractByIdInclusive​(Expression expression, Schema schema, boolean caseSensitive, int... ids)
      Extracts an expression that references only the given column IDs from the given expression.
      static Expression sanitize​(Expression expr)
      Produces an unbound Expression with the same structure, but with data values replaced by descriptions.
      static boolean selectsPartitions​(Expression expr, PartitionSpec spec, boolean caseSensitive)
      Returns whether an expression selects whole partitions for a partition spec.
      static boolean selectsPartitions​(Expression expr, Table table, boolean caseSensitive)
      Returns whether an expression selects whole partitions for all partition specs in a table.
      static java.lang.String toSanitizedString​(Expression expr)
      Produces a sanitized expression string with the same structure, but with data values replaced by descriptions.
      • Methods inherited from class java.lang.Object

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

      • sanitize

        public static Expression sanitize​(Expression expr)
        Produces an unbound Expression with the same structure, but with data values replaced by descriptions.

        Numbers are replaced with magnitude and type, string-like values are replaced by hashes, and date/time values are replaced by the type.

        Parameters:
        expr - an Expression to sanitize
        Returns:
        a sanitized Expression
      • toSanitizedString

        public static java.lang.String toSanitizedString​(Expression expr)
        Produces a sanitized expression string with the same structure, but with data values replaced by descriptions.

        Numbers are replaced with magnitude and type, string-like values are replaced by hashes, and date/time values are replaced by the type.

        Parameters:
        expr - an Expression to sanitize
        Returns:
        a sanitized expression string
      • extractByIdInclusive

        public static Expression extractByIdInclusive​(Expression expression,
                                                      Schema schema,
                                                      boolean caseSensitive,
                                                      int... ids)
        Extracts an expression that references only the given column IDs from the given expression.

        The result is inclusive. If a row would match the original filter, it must match the result filter.

        Parameters:
        expression - a filter Expression
        schema - a Schema
        caseSensitive - whether binding is case sensitive
        ids - field IDs used to match predicates to extract from the expression
        Returns:
        an Expression that selects at least the same rows as the original using only the IDs
      • equivalent

        public static boolean equivalent​(Expression left,
                                         Expression right,
                                         Types.StructType struct,
                                         boolean caseSensitive)
        Returns whether two unbound expressions will accept the same inputs.

        If this returns true, the expressions are guaranteed to return the same evaluation for the same input. However, if this returns false the expressions may return the same evaluation for the same input. That is, expressions may be equivalent even if this returns false.

        Parameters:
        left - an unbound expression
        right - an unbound expression
        struct - a struct type for binding
        caseSensitive - whether to bind expressions using case-sensitive matching
        Returns:
        true if the expressions are equivalent
      • selectsPartitions

        public static boolean selectsPartitions​(Expression expr,
                                                Table table,
                                                boolean caseSensitive)
        Returns whether an expression selects whole partitions for all partition specs in a table.

        For example, ts < '2021-03-09T10:00:00.000' selects whole partitions in an hourly spec, [hours(ts)], but does not select whole partitions in a daily spec, [days(ts)].

        Parameters:
        expr - an unbound expression
        table - a table
        caseSensitive - whether expression binding should be case sensitive
        Returns:
        true if the expression will select whole partitions in all table specs
      • selectsPartitions

        public static boolean selectsPartitions​(Expression expr,
                                                PartitionSpec spec,
                                                boolean caseSensitive)
        Returns whether an expression selects whole partitions for a partition spec.

        For example, ts < '2021-03-09T10:00:00.000' selects whole partitions in an hourly spec, [hours(ts)], but does not select whole partitions in a daily spec, [days(ts)].

        Parameters:
        expr - an unbound expression
        spec - a partition spec
        Returns:
        true if the expression will select whole partitions in the given spec
      • describe

        public static java.lang.String describe​(Term term)