Reputation: 43
I've got this data:
(15,ArrayBuffer((1038,1)))
(14,ArrayBuffer((1031,1), (1003,1)))
(110,ArrayBuffer((1035,1))
so Group and Map have already been executed. Now I have to do a Reduce Step, the result that I want is:
(15,1)
(14,2)
(110,1)
a simply count map-reduce. But I can not write a reduce Step ( I have to do write a sum of any 1 term -dummy- in array buffer)
Upvotes: 0
Views: 60
Reputation: 3470
Hi you can use a map and the size of the ArrayBuffer
import scala.collection.mutable._
Seq((15,ArrayBuffer((1038,1)))
,(14,ArrayBuffer((1031,1),(1003,1)))
,(110,ArrayBuffer((1035,1))))
.map { case (x,y) => (x,y.size) }
res2: scala.collection.mutable.Seq[(Int, Int)] = ArrayBuffer((15,1), (14,2), (110,1))
Upvotes: 3