Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark: Expansion of RDD(Key, List) to RDD(Key, Value)

So I have an RDD of something like this

RDD[(Int, List)]]

Where a single element in the RDD looks like

(1, List(1, 2, 3))

My question is how can I expand the key value pair to something like this

(1,1)
(1,2)
(1,3)

Thank you

like image 737
adrian Avatar asked Apr 04 '16 00:04

adrian


Video Answer


1 Answers

rdd.flatMap { case (key, values) => values.map((key, _)) }

like image 115
Sean Owen Avatar answered Nov 15 '22 08:11

Sean Owen