我有一个如下的RDD,并希望按循环的索引号访问每一行中的元素。这可能吗?
(98,(344,(Dead Man Walking (1995),0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0)))
(50,(501,(Richard III (1995),0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1)))
(1,(321,(Toy Story (1995),0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0)))
到目前为止,我已经提出了以下代码
val combgenr = mvnmcnt.map(x => (x._2._2.productIterator.foreach{
var n = 4
i => (
if (i == "1") {println((x._1.toInt,x._2._1.toInt,x._2._2._1),n)
})
n += 1
}))
但是我在结果中得到了额外的一行(如下),这是我不知道的原因。
((98,344,Dead Man Walking (1995)),13)
()
((50,501,Richard III (1995)),13)
((50,501,Richard III (1995)),22)
((50,501,Richard III (1995)),23)
()
((1,321,Toy Story (1995)),8)
((1,321,Toy Story (1995)),9)
((1,321,Toy Story (1995)),10)
()
有什么想法吗?