isEmpty

isEmpty returns a Boolean value as True, if the RDD contains no element at all. It is important to note that RDD can be empty even when it is one or more partition. In the following example, we create the RDD with three integers and then filter an element that does not exist in the parent RDD hence the resultant creates an empty RDD:

Java 7:

// isEmpty
JavaRDD<Integer> intRDD = sparkContext.parallelize(Arrays.asList(1,2,3));
boolean isRDDEmpty = intRDD.filter(new Function<Integer, Boolean>() {
@Override
public Boolean call(Integer v1) throws Exception {
return v1.equals(5);
}
}).isEmpty();
System.out.println("The RDD is empty ::"+isRDDEmpty);

Java 8:

JavaRDD<Integer> intRDD = sparkContext.parallelize(Arrays.asList(1,2,3));
boolean isRDDEmpty= intRDD.filter(a-> a.equals(5)).isEmpty();
System.out.println("The RDD is empty ::"+isRDDEmpty);
..................Content has been hidden....................

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