File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
main/scala/org/apache/spark/rdd
test/scala/org/apache/spark/rdd Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ import org.apache.spark.util.StatCounter
3131class DoubleRDDFunctions (self : RDD [Double ]) extends Logging with Serializable {
3232 /** Add up the elements in this RDD. */
3333 def sum (): Double = {
34- self.reduce (_ + _)
34+ self.fold( 0.0 ) (_ + _)
3535 }
3636
3737 /**
Original file line number Diff line number Diff line change 1818package org .apache .spark .rdd
1919
2020import org .scalatest .FunSuite
21+ import org .scalatest .Matchers ._
2122
2223import org .apache .spark ._
2324
2425class DoubleRDDSuite extends FunSuite with SharedSparkContext {
26+ test(" sum" ) {
27+ sc.parallelize(Seq .empty[Double ]).sum() should be(0.0 +- 0.0001 )
28+ sc.parallelize(Seq (1.0 )).sum() should be(1.0 +- 0.0001 )
29+ sc.parallelize(Seq (1.0 , 2.0 )).sum() should be(3.0 +- 0.0001 )
30+ }
31+
2532 // Verify tests on the histogram functionality. We test with both evenly
2633 // and non-evenly spaced buckets as the bucket lookup function changes.
2734 test(" WorksOnEmpty" ) {
You can’t perform that action at this time.
0 commit comments