Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何创建自定义列表累加器,即列表[(Int,Int)]?_Scala_Apache Spark_Accumulator - Fatal编程技术网

Scala 如何创建自定义列表累加器,即列表[(Int,Int)]?

Scala 如何创建自定义列表累加器,即列表[(Int,Int)]?,scala,apache-spark,accumulator,Scala,Apache Spark,Accumulator,我正在尝试使用ApacheSpark中的自定义累加器在列表中累加对。 结果应该有List[(Int,Int)]type。为此,我创建了自定义累加器: import org.apache.spark.AccumulatorParam class AccumPairs extends AccumulatorParam[List[(Int,Int)]] { def zero(initialValue: List[(Int,Int)]): List[(Int,Int)] = {

我正在尝试使用ApacheSpark中的自定义累加器在列表中累加对。 结果应该有
List[(Int,Int)]
type。为此,我创建了自定义累加器:

import org.apache.spark.AccumulatorParam

class AccumPairs extends AccumulatorParam[List[(Int,Int)]] {

    def zero(initialValue: List[(Int,Int)]): List[(Int,Int)] = {
      List()
    }

    def addInPlace(l1: List[(Int,Int)], l2: List[(Int,Int)]): List[(Int,Int)] = {
      l1 ++ l2
    }

 }
但是我不能实例化这种类型的变量

val pairAccum = sc.accumulator(new List():List[(Int,Int)])(AccumPairs)
结果是错误的。请帮忙。

这一款有效:

val pairAccum = sc.accumulator(List[(Int,Int)]())( new AccumPairs)

没有参数的类没有多大意义(如果有的话),因为您“隐式”创建了一个值1。将关键字
class
更改为
object
,您的示例将起作用

改变

class AccumPairs extends AccumulatorParam[List[(Int,Int)]] {

[1] 您仍然可以创建该类的多个实例,但它们实际上是相似的

object AccumPairs extends AccumulatorParam[List[(Int,Int)]] {