Skip to content
Snippets Groups Projects
Commit 8fbd45c7 authored by Olivier Girardot's avatar Olivier Girardot Committed by Reynold Xin
Browse files

SPARK-6993 : Add default min, max methods for JavaDoubleRDD

The default method will use Guava's Ordering instead of
java.util.Comparator.naturalOrder() because it's not available
in Java 7, only in Java 8.

Author: Olivier Girardot <o.girardot@lateral-thoughts.com>

Closes #5571 from ogirardot/master and squashes the following commits:

7fe2e9e [Olivier Girardot] SPARK-6993 : Add default min, max methods for JavaDoubleRDD
parent 729885ec
No related branches found
No related tags found
No related merge requests found
......@@ -163,6 +163,20 @@ class JavaDoubleRDD(val srdd: RDD[scala.Double])
/** Add up the elements in this RDD. */
def sum(): JDouble = srdd.sum()
/**
* Returns the minimum element from this RDD as defined by
* the default comparator natural order.
* @return the minimum of the RDD
*/
def min(): JDouble = min(com.google.common.collect.Ordering.natural())
/**
* Returns the maximum element from this RDD as defined by
* the default comparator natural order.
* @return the maximum of the RDD
*/
def max(): JDouble = max(com.google.common.collect.Ordering.natural())
/**
* Return a [[org.apache.spark.util.StatCounter]] object that captures the mean, variance and
* count of the RDD's elements in one operation.
......
......@@ -761,6 +761,20 @@ public class JavaAPISuite implements Serializable {
Assert.assertEquals(1.0, max, 0.001);
}
@Test
public void naturalMax() {
JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
double max = rdd.max();
Assert.assertTrue(4.0 == max);
}
@Test
public void naturalMin() {
JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
double max = rdd.min();
Assert.assertTrue(1.0 == max);
}
@Test
public void takeOrdered() {
JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment