forEach

In order to iterate over all the elements of the RDD to perform some repetitive tasks without fetching the entire set of data to the Driver program can be achieved by using the foreach() function:

Java 7:

//forEach()
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 2, 3,4,5),3);
intRDD.foreach(newVoidFunction<Integer>() {
@Override
public void call(Integer t) throws Exception {
System.out.println("The element values of the RDD are ::"+t);
}
});

Java 8:

JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 2, 3,4,5),3);
intRDD.foreach(x->System.out.println("The element values of the RDD are ::"+x));
..................Content has been hidden....................

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