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
31
31
class DoubleRDDFunctions (self : RDD [Double ]) extends Logging with Serializable {
32
32
/** Add up the elements in this RDD. */
33
33
def sum (): Double = {
34
- self.reduce (_ + _)
34
+ self.fold( 0.0 ) (_ + _)
35
35
}
36
36
37
37
/**
Original file line number Diff line number Diff line change 18
18
package org .apache .spark .rdd
19
19
20
20
import org .scalatest .FunSuite
21
+ import org .scalatest .Matchers ._
21
22
22
23
import org .apache .spark ._
23
24
24
25
class 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
+
25
32
// Verify tests on the histogram functionality. We test with both evenly
26
33
// and non-evenly spaced buckets as the bucket lookup function changes.
27
34
test(" WorksOnEmpty" ) {
You can’t perform that action at this time.
0 commit comments