Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/org/apache/spark/JavaAPISuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,20 @@ public void min() {
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));
Expand Down