Marco_Z
Marco_Z

Reputation: 43

Reduce in scala (not Spark)

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

Answers (1)

uh_big_mike_boi
uh_big_mike_boi

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

Related Questions