【问题标题】:CombineBy Key implementation error: value _1 is not a member of DoubleCombineBy Key 实现错误:值 _1 不是 Double 的成员
【发布时间】:2018-10-16 00:44:59
【问题描述】:

我是 scala 和 spark 的新手。有人可以在使用 combineByKey 时帮助我理解以下错误。

val combineRdd = filterRdd.combineByKey( (value : Double) => (value  ,1)  , (acc : Double , value : Double) => ( (acc._1 + value ) , (acc._2 +1)) , (acc : Double, value : Double) => acc._1 + value._1 , acc._2 + value._2) 

Filter Rdd 就是

scala> filterRdd.first
res6: (Int, Double) = (1,299.98)

错误是 :31: error: value _1 is not a member of Double

【问题讨论】:

  • value 是一个Double,但您像元组一样访问它。它没有_1
  • combineByKey 中的 3 个闭包中的变量名称是否与 3 个函数有任何联系?
  • 不,变量名之间没有“链接”。
  • 是的,我使用了(acc : Double, value : Double) => acc._1 + value._1 , acc._2 + value._2) 第三次闭包,就好像在第三次闭包中是正确的一样,我们正在累积所有分区的值。我不确定我在哪里使用它作为元组,但是我知道我在(acc : Double , value : Double) => ( (acc._1 + value ) , (acc._2 +1)) 中有一些错误(acc:Double 实际上是一个具有值(值,1)的元组,我使用 Double 作为类型。请建议和如果我错了,请纠正我

标签: apache-spark


【解决方案1】:

这是正确的代码

val combineRdd = filterRdd.combineByKey( (value : Double) => (value ,1) , (acc : (Double, Int) , value : Double) => ( (acc._1 + value ) , (acc._2 +1)) , (acc : (Double , Int), value : (Double,Int ) ) => (acc._1 + value._1 , acc._2 + value._2)) combineRdd: org.apache.spark.rdd.RDD[(Int, (Double, Int))] = ShuffledRDD[3] at combineByKey at <console>:31

【讨论】:

    猜你喜欢
    • 2016-05-01
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2017-10-22
    • 2015-10-03
    • 2020-03-25
    • 2020-04-27
    相关资源
    最近更新 更多