Max

The action max returns the largest value in the RDD where the comparison between the elements is decided by the comparator passed as an argument:

Java 7:

// max()
JavaRDD<Integer> intRDD = sparkContext.parallelize(Arrays.asList(1,2,3));
Integer maxVal=intRDD.max(new integerComparator());
System.out.println("The max value of RDD is "+maxVal);
//Also create a Comparator class as below
static class integer Comparator implements Comparator<Integer>, Serializable
{
private static finallongserialVersionUID = 1L;
@Override
public int compare(Integer a, Integer b) {
return a.compareTo(b);
}
}

Java 8:

JavaRDD<Integer> intRDD = sparkContext.parallelize(Arrays.asList(1,2,3));
Integer maxVal=intRDD.max(Comparator.naturalOrder());
System.out.println("The max value of RDD is "+maxVal);
..................Content has been hidden....................

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