将RDD中的元组分解为两个元组

时间:2016-01-07 07:41:46

标签: scala apache-spark rdd iterable

我有RDD[(String, (Iterable[Int], Iterable[Coordinate]))] 我想做的是将Iterable[Int]分解为元组,每个元组都像(String,Int,Iterable[Coordinate])

举个例子,我想改造:

('a',<1,2,3>,<(45.34,32.33),(45.36,32.34)>)
('b',<1>,<(46.64,32.66),(46.67,32.71)>)

('a',1,<(45.34,32.33),(45.36,32.34)>)
('a',2,<(45.34,32.33),(45.36,32.34)>)
('a',3,<(45.34,32.33),(45.36,32.34)>)
('b',1,<(46.64,32.66),(46.67,32.71)>)

Scala是如何完成的?

1 个答案:

答案 0 :(得分:6)

尝试使用flatMap:

rdd.flatMap {case (v, i1, i2) => i1.map(i=>(v, i, i2)}