Skip to content
Snippets Groups Projects
Commit 51b306b9 authored by Erik van Oosten's avatar Erik van Oosten Committed by Sean Owen
Browse files

SPARK-6878 [CORE] Fix for sum on empty RDD fails with exception

Author: Erik van Oosten <evanoosten@ebay.com>

Closes #5489 from erikvanoosten/master and squashes the following commits:

1c91954 [Erik van Oosten] Rewrote double range matcher to an exact equality assert (SPARK-6878)
f1708c9 [Erik van Oosten] Fix for sum on empty RDD fails with exception (SPARK-6878)
parent 628a72f7
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ import org.apache.spark.util.StatCounter ...@@ -31,7 +31,7 @@ import org.apache.spark.util.StatCounter
class DoubleRDDFunctions(self: RDD[Double]) extends Logging with Serializable { class DoubleRDDFunctions(self: RDD[Double]) extends Logging with Serializable {
/** Add up the elements in this RDD. */ /** Add up the elements in this RDD. */
def sum(): Double = { def sum(): Double = {
self.reduce(_ + _) self.fold(0.0)(_ + _)
} }
/** /**
......
...@@ -22,6 +22,12 @@ import org.scalatest.FunSuite ...@@ -22,6 +22,12 @@ import org.scalatest.FunSuite
import org.apache.spark._ import org.apache.spark._
class DoubleRDDSuite extends FunSuite with SharedSparkContext { class DoubleRDDSuite extends FunSuite with SharedSparkContext {
test("sum") {
assert(sc.parallelize(Seq.empty[Double]).sum() === 0.0)
assert(sc.parallelize(Seq(1.0)).sum() === 1.0)
assert(sc.parallelize(Seq(1.0, 2.0)).sum() === 3.0)
}
// Verify tests on the histogram functionality. We test with both evenly // Verify tests on the histogram functionality. We test with both evenly
// and non-evenly spaced buckets as the bucket lookup function changes. // and non-evenly spaced buckets as the bucket lookup function changes.
test("WorksOnEmpty") { test("WorksOnEmpty") {
......
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