aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorErik van Oosten <evanoosten@ebay.com>2015-04-14 12:39:56 +0100
committerSean Owen <sowen@cloudera.com>2015-04-14 12:39:56 +0100
commit51b306b930cfe03ad21af72a3a6ef31e6e626235 (patch)
tree14dd70aab48b870a648f3992f66180c8df706a28 /core
parent628a72f70ed06b8d7aee81cfb16070eb2c87b9cd (diff)
downloadspark-51b306b930cfe03ad21af72a3a6ef31e6e626235.tar.gz
spark-51b306b930cfe03ad21af72a3a6ef31e6e626235.tar.bz2
spark-51b306b930cfe03ad21af72a3a6ef31e6e626235.zip
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)
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala2
-rw-r--r--core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala6
2 files changed, 7 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala b/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
index 29ca3e9c4b..843a893235 100644
--- a/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
+++ b/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
@@ -31,7 +31,7 @@ import org.apache.spark.util.StatCounter
class DoubleRDDFunctions(self: RDD[Double]) extends Logging with Serializable {
/** Add up the elements in this RDD. */
def sum(): Double = {
- self.reduce(_ + _)
+ self.fold(0.0)(_ + _)
}
/**
diff --git a/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala b/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
index 97079382c7..01039b9449 100644
--- a/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
+++ b/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
@@ -22,6 +22,12 @@ import org.scalatest.FunSuite
import org.apache.spark._
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
// and non-evenly spaced buckets as the bucket lookup function changes.
test("WorksOnEmpty") {