如何在scala中迭代accumulableCollection

时间:2016-01-26 02:43:54

标签: scala indexing collections

你能给一些代码片段如何迭代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) 

1 个答案:

答案 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)