This question is regarding groupByKey() in spark using scala.
Consider below data
Name,marks,value
Chris,30,1
Chris,35,1
Robert,12,1
Robert,20,1
Created below rdd
val dataRDD = sc.parallelize(List(("Chris",30,1),("Chris",35,1),("Robert",12,1),("Robert",20,1)))
I am trying to create a key value pair of this like
val kvRDD = dataRDD.map(rec=> (rec._1, (rec._2,rec._3)))
Now I want sum of both the values.
val sumRDD = kvRDD.groupByKey().map(rec => (rec._1,(rec._2._1.sum, rec._2._2.sum)))
However, I am facing below error.
<console>:28: error: value _2 is not a member of Iterable[(Int, Int)]
Can't we achieve the required using groupByKey
?