Yoav
Yoav

Reputation: 1029

Break tuple in RDD to two tuples

I have an RDD[(String, (Iterable[Int], Iterable[Coordinate]))] What I would like to do, is to break the Iterable[Int] to tuples, that each one will be like (String,Int,Iterable[Coordinate])

For an example, I would like to transform:

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

to

('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)>)

How is done is Scala?

Upvotes: 2

Views: 828

Answers (1)

Nyavro
Nyavro

Reputation: 8866

Try to use flatMap:

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

Upvotes: 6

Related Questions