[英]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. 因此Group和Map已经执行。 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)
但是我不能写一个reduce步骤(我必须在数组缓冲区中写任何1个-dummy-的和)
Hi you can use a map and the size of the ArrayBuffer 嗨,您可以使用地图和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)) res2:scala.collection.mutable.Seq [(Int,Int)] = ArrayBuffer((15,1),(14,2),(110,1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.