Filter

Javadoc Javadoc


Given a predicate, filter out all elements that don’t satisfy that predicate. May also be used to filter based on an inequality with a given value based on the natural ordering of the element.

Examples

Example 1: Filtering with a predicate

PCollection<String> allStrings = Create.of("Hello", "world", "hi");
PCollection<String> longStrings = allStrings
    .apply(Filter.by(new SerializableFunction<String, Boolean>() {
      @Override
      public Boolean apply(String input) {
        return input.length() > 3;
      }
    }));
The result is a PCollection containing “Hello” and “world”.

Example 2: Filtering with an inequality

PCollection<Long> numbers = Create.of(1L, 2L, 3L, 4L, 5L);
PCollection<Long> bigNumbers = numbers.apply(Filter.greaterThan(3));
PCollection<Long> smallNumbers = numbers.apply(Filter.lessThanEq(3));
Other variants include Filter.greaterThanEq, Filter.lessThan and Filter.equal.

Example 3: Filtering with lambda