Spark2 AccumulatorV2累加器

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

posted @ 2016-11-15 21:19  智能先行者  阅读(2400)  评论(0编辑  收藏  举报