Filter

With a filter transformation, the function is executed on all the elements of the source RDD and only those elements, for which the function returns true, are selected to form the target RDD. In this transformation, the number of elements in target RDD can be less than or equal to the number of elements in the source RDD.

The following is an example of a filter transformation that runs on the RDD of integers and selects only even elements, that is, elements that are divisible by 2:

A filter transformation can be executed using Java 7 on intRDD created in the previous examples as follows:


intRDD .filter(new Function<Integer, Boolean>() {
@Override
public Boolean call(Integer x ) throws Exception {
return ( x % 2 == 0);
}
});

Example of intRDD using Java 8:

intRDD.filter(x -> (x % 2 == 0));
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156