Class FilterApi

java.lang.Object
org.apache.parquet.filter2.predicate.FilterApi

public final class FilterApi extends Object
The Filter API is expressed through these static methods.

Example usage:

   IntColumn foo = intColumn("foo");
   DoubleColumn bar = doubleColumn("x.y.bar");

   // foo == 10 || bar <= 17.0
   FilterPredicate pred = or(eq(foo, 10), ltEq(bar, 17.0));
 
  • Method Details

    • intColumn

      public static Operators.IntColumn intColumn(String columnPath)
    • longColumn

      public static Operators.LongColumn longColumn(String columnPath)
    • floatColumn

      public static Operators.FloatColumn floatColumn(String columnPath)
    • doubleColumn

      public static Operators.DoubleColumn doubleColumn(String columnPath)
    • booleanColumn

      public static Operators.BooleanColumn booleanColumn(String columnPath)
    • binaryColumn

      public static Operators.BinaryColumn binaryColumn(String columnPath)
    • eq

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsEqNotEq> Operators.Eq<T> eq(C column, T value)
      Keeps records if their value is equal to the provided value. Nulls are treated the same way the java programming language does.

      For example: eq(column, null) will keep all records whose value is null. eq(column, 7) will keep all records whose value is 7, and will drop records whose value is null

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      an equals predicate for the given column and value
    • notEq

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsEqNotEq> Operators.NotEq<T> notEq(C column, T value)
      Keeps records if their value is not equal to the provided value. Nulls are treated the same way the java programming language does.

      For example: notEq(column, null) will keep all records whose value is not null. notEq(column, 7) will keep all records whose value is not 7, including records whose value is null.

      NOTE: this is different from how some query languages handle null. For example, SQL and pig will drop nulls when you filter by not equal to 7. To achieve similar behavior in this api, do: and(notEq(column, 7), notEq(column, null))

      NOTE: be sure to read the lt(C, T), ltEq(C, T), gt(C, T), gtEq(C, T) operator's docs for how they handle nulls

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      a not-equals predicate for the given column and value
    • lt

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsLtGt> Operators.Lt<T> lt(C column, T value)
      Keeps records if their value is less than (but not equal to) the provided value. The provided value cannot be null, as less than null has no meaning. Records with null values will be dropped.

      For example: lt(column, 7) will keep all records whose value is less than (but not equal to) 7, and not null.

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      a less-than predicate for the given column and value
    • ltEq

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsLtGt> Operators.LtEq<T> ltEq(C column, T value)
      Keeps records if their value is less than or equal to the provided value. The provided value cannot be null, as less than null has no meaning. Records with null values will be dropped.

      For example: ltEq(column, 7) will keep all records whose value is less than or equal to 7, and not null.

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      a less-than-or-equal predicate for the given column and value
    • gt

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsLtGt> Operators.Gt<T> gt(C column, T value)
      Keeps records if their value is greater than (but not equal to) the provided value. The provided value cannot be null, as less than null has no meaning. Records with null values will be dropped.

      For example: gt(column, 7) will keep all records whose value is greater than (but not equal to) 7, and not null.

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      a greater-than predicate for the given column and value
    • gtEq

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsLtGt> Operators.GtEq<T> gtEq(C column, T value)
      Keeps records if their value is greater than or equal to the provided value. The provided value cannot be null, as less than null has no meaning. Records with null values will be dropped.

      For example: gtEq(column, 7) will keep all records whose value is greater than or equal to 7, and not null.

      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      value - a value that matches the column's type
      Returns:
      a greater-than-or-equal predicate for the given column and value
    • in

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsEqNotEq> Operators.In<T> in(C column, Set<T> values)
      Keeps records if their value is in the provided values. The provided values set could not be null, but could contains a null value.

      For example:

         
         Set<Integer> set = new HashSet<>();
         set.add(9);
         set.add(null);
         set.add(50);
         in(column, set);
       
      will keep all records whose values are 9, null, or 50.
      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      values - a set of values that match the column's type
      Returns:
      an in predicate for the given column and value
    • notIn

      public static <T extends Comparable<T>, C extends Operators.Column<T> & Operators.SupportsEqNotEq> Operators.NotIn<T> notIn(C column, Set<T> values)
      Keeps records if their value is not in the provided values. The provided values set could not be null, but could contains a null value.

      For example:

         
         Set<Integer> set = new HashSet<>();
         set.add(9);
         set.add(null);
         set.add(50);
         notIn(column, set);
       
      will keep all records whose values are not 9, null, and 50.
      Type Parameters:
      T - the Java type of values in the column
      C - the column type that corresponds to values of type T
      Parameters:
      column - a column reference created by FilterApi
      values - a set of values that match the column's type
      Returns:
      an notIn predicate for the given column and value
    • contains

      public static <T extends Comparable<T>, P extends org.apache.parquet.filter2.predicate.Operators.SingleColumnFilterPredicate<T>> Operators.Contains<T> contains(P pred)
    • userDefined

      public static <T extends Comparable<T>, U extends UserDefinedPredicate<T>> Operators.UserDefined<T,U> userDefined(Operators.Column<T> column, Class<U> clazz)
      Keeps records that pass the provided UserDefinedPredicate

      The provided class must have a default constructor. To use an instance of a UserDefinedPredicate instead, see userDefined below.

      Type Parameters:
      T - the Java type of values in the column
      U - a user-defined predicate for values of type T
      Parameters:
      column - a column reference created by FilterApi
      clazz - a user-defined predicate class
      Returns:
      a user-defined predicate for the given column
    • userDefined

      public static <T extends Comparable<T>, U extends UserDefinedPredicate<T> & Serializable> Operators.UserDefined<T,U> userDefined(Operators.Column<T> column, U udp)
      Keeps records that pass the provided UserDefinedPredicate

      The provided instance of UserDefinedPredicate must be serializable.

      Type Parameters:
      T - the Java type of values in the column
      U - a user-defined predicate for values of type T
      Parameters:
      column - a column reference created by FilterApi
      udp - a user-defined predicate instance
      Returns:
      a user-defined predicate for the given column
    • and

      public static FilterPredicate and(FilterPredicate left, FilterPredicate right)
      Constructs the logical and of two predicates. Records will be kept if both the left and right predicate agree that the record should be kept.
      Parameters:
      left - a predicate
      right - a predicate
      Returns:
      an and predicate from the result of the left and right predicates
    • or

      public static FilterPredicate or(FilterPredicate left, FilterPredicate right)
      Constructs the logical or of two predicates. Records will be kept if either the left or right predicate is satisfied (or both).
      Parameters:
      left - a predicate
      right - a predicate
      Returns:
      an or predicate from the result of the left and right predicates
    • not

      public static FilterPredicate not(FilterPredicate predicate)
      Constructs the logical not (or inverse) of a predicate. Records will be kept if the provided predicate is not satisfied.
      Parameters:
      predicate - a predicate
      Returns:
      a not predicate wrapping the result of the given predicate