1
需要如下輸出:(167,5)。我想年齡之和計算spark aggregateByKey - 給出類型不匹配錯誤
val people = List(("Ganga",43,'F'),("John",28,'M'),("Lolitha",33,'F'),("Don't Know",18,'T'))
val peopleRDD = sc.parallelize(people)
val kv = peopleRDD.map(x=>((x._1,x._3),x._2))
val result = kv.aggregateByKey(0,0)((x : (Int,Int) , y : Int)=> (x._1+y,x._2+1),(x:(Int,Int),y:(Int,Int))=>(x._1+y._1,x._2+y._2))
得到一個錯誤的結果爲:
console>:33: error: type mismatch; found : (Int, Int) required: Int
val result = kv.aggregateByKey(0,0)((x : (Int,Int) , y : Int)=> (x._1+y,x._2+1),(x:(Int,Int),y:(Int,Int))=>(x._1+y._1,x._2+y._2))
哪裏'167,5'從何而來?當我總結年齡並且計數似乎是4時,我沒有得到這個數字。 – Psidom