Repository: spark
Updated Branches:
  refs/heads/branch-1.2 daec1c635 -> 899ffdcc0


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

Author: Erik van Oosten <evanoos...@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)

(cherry picked from commit 51b306b930cfe03ad21af72a3a6ef31e6e626235)
Signed-off-by: Sean Owen <so...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/899ffdcc
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/899ffdcc
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/899ffdcc

Branch: refs/heads/branch-1.2
Commit: 899ffdcc06bf0fcd40387d73e8a3fddfc72cb33a
Parents: daec1c6
Author: Erik van Oosten <evanoos...@ebay.com>
Authored: Tue Apr 14 12:39:56 2015 +0100
Committer: Sean Owen <so...@cloudera.com>
Committed: Tue Apr 14 12:40:23 2015 +0100

----------------------------------------------------------------------
 .../main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala   | 2 +-
 core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala  | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/899ffdcc/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
----------------------------------------------------------------------
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 e66c06e..04b52d9 100644
--- a/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
+++ b/core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
@@ -32,7 +32,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)(_ + _)
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/spark/blob/899ffdcc/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
----------------------------------------------------------------------
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 e29ac0c..7d1ed06 100644
--- a/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
+++ b/core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
@@ -23,6 +23,12 @@ import org.apache.spark._
 import org.apache.spark.SparkContext._
 
 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") {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to