我想在Apache Spark中使用自定義累加器來累積一組。結果應該是Set [String]類型。對於這個我創建自定義累加器:如何創建自定義累加器,即Set [String]?
object SetAccumulatorParam extends AccumulatorParam[Set[String]] {
def addInPlace(r1: mutable.Set[String], r2: mutable.Set[String]): mutable.Set[String] = {
r1 ++= r2
}
def zero(initialValue: mutable.Set[String]): mutable.Set[String] = {
Set()
}
}
但我不能實例化這種類型的變量。
val tags = sc.accumulator(Set(""))(SetAccumulatorParam)
導致錯誤。請幫助。
required: org.apache.spark.AccumulatorParam[Set[String]]
你做了什麼樣子,從官方文檔(HTTP很大的不同://spark.apache。組織/文檔/最新/編程-guide.html#蓄電池)。我也對這裏使用的對象持懷疑態度,因爲我會假設Spark想要在某個時刻實例化這個累加器。 – LiMuBei