diff options
author | Olivier Girardot <o.girardot@lateral-thoughts.com> | 2015-04-18 18:21:44 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2015-04-18 18:21:44 -0700 |
commit | 8fbd45c74e762dd6b071ea58a60f5bb649f74042 (patch) | |
tree | 25020add52beba0bee45c55f22ea203d349026c0 | |
parent | 729885ec6b4be61144d04821f1a6e8d2134eea00 (diff) | |
download | spark-8fbd45c74e762dd6b071ea58a60f5bb649f74042.tar.gz spark-8fbd45c74e762dd6b071ea58a60f5bb649f74042.tar.bz2 spark-8fbd45c74e762dd6b071ea58a60f5bb649f74042.zip |
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
-rw-r--r-- | core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala | 14 | ||||
-rw-r--r-- | core/src/test/java/org/apache/spark/JavaAPISuite.java | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala b/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala index 79e4ebf2db..61af867b11 100644 --- a/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala +++ b/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala @@ -164,6 +164,20 @@ class JavaDoubleRDD(val srdd: RDD[scala.Double]) 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. */ diff --git a/core/src/test/java/org/apache/spark/JavaAPISuite.java b/core/src/test/java/org/apache/spark/JavaAPISuite.java index d4b5bb5191..8a4f2a08fe 100644 --- a/core/src/test/java/org/apache/spark/JavaAPISuite.java +++ b/core/src/test/java/org/apache/spark/JavaAPISuite.java @@ -762,6 +762,20 @@ public class JavaAPISuite implements Serializable { } @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)); Assert.assertEquals(Arrays.asList(1.0, 2.0), rdd.takeOrdered(2, new DoubleComparator())); |