你能给一些代码片段如何迭代acc
吗?
val acc: Accumulable[mutable.HashSet[String], String] = sc.accumulableCollection(scala.collection.mutable.HashSet[String]())
特别是,我需要将acc
编号为连续编号。
例如,如果acc有两个元素' apple'和' aravind'如下。
org.apache.spark.Accumulable[scala.collection.mutable.HashSet[String],String] = Set(apple, aravind)
我想拥有(比如zipWithIndex,但从1开始,订单并不重要)
(apple, 1)
(aravid,2)
答案 0 :(得分:1)
Only the driver program can read the accumulator’s value, using its
value
method.
所以(实际累积acc
之后):
val acc1 = acc.value
Range.Inclusive(1, acc1.size).zip(acc1.toList)