Spark2 AccumulatorV2累加器

智慧先行者發表於2016-11-15

Accumulator.scala  (Since version 2.0.0) use AccumulatorV2

 

import org.apache.spark.util._

val accum=new DoubleAccumulator()

Array(1, 2, 3, 4).foreach(x => accum.add(x))

 

 accum.value

res4: Double = 10.0

 

accum.avg

res5: Double = 2.5

 

accum.count

res6: Long = 4

 

accum.sum

res7: Double = 10.0

相關文章