-
Notifications
You must be signed in to change notification settings - Fork 0
/
accumulator.scala
36 lines (24 loc) · 993 Bytes
/
accumulator.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import scala.collection._
val logMetadataAccumulator = sc.accumulableCollection(mutable.ArrayBuffer[(
String, String, Long, String, Long, Long)]())
logMetadataAccumulator += (fileName, logType, numLines, logSource, startTime, endTime)
Row( 0L, "blah" "blah", 0L )
//
accumulator[T](initialValue: T)(implicit param: AccumulatorParam[T]): Accumulator[T]
accumulator[T](initialValue: T, name: String)(implicit param: AccumulatorParam[T]): Accumulator[T]
accumulator methods create accumulators of type T with the initial value initialValue.
scala> val acc = sc.accumulator(0) // not needed for example
acc: org.apache.spark.Accumulator[Int] = 0
scala> val counter = sc.accumulator(0, "counter")
counter: org.apache.spark.Accumulator[Int] = 0
scala> counter.value
res2: Int = 0
scala> sc.parallelize(0 to 9).foreach(n => counter += n)
scala> counter.value
res4: Int = 45
//Scala do-while Loops
var count = 0
do {
count += 1
println(count)
} while (count < 4.99)