Skip to content

Commit

Permalink
SPARK-6878 [CORE] Fix for sum on empty RDD fails with exception
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Erik van Oosten authored and srowen committed Apr 14, 2015
1 parent 628a72f commit 51b306b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)(_ + _)
}

/**
Expand Down
6 changes: 6 additions & 0 deletions core/src/test/scala/org/apache/spark/rdd/DoubleRDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 51b306b

Please sign in to comment.