You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Abhishek Shivkumar <ab...@gmail.com> on 2015/12/13 18:40:22 UTC

How to unpack the values of an item in a RDD so I can create a RDD with multiple items?

Hi,

    I have a RDD of many items.

Each item has a key and its value is a list of elements.

I want to unpack the elements of the item so that I can create a new RDD
with each of its item being the original key and one single element.

I tried doing RDD.flatmap(lambda line: [ (line[0], v) for v in line[1]])

but it throws an error saying "AttributeError: 'PipelinedRDD' object has no
attribute 'flatmap"

Can someone tell me the right way to unpack the values to different items
in the new RDD?

Thank you!

With Regards,
Abhishek S

Re: How to unpack the values of an item in a RDD so I can create a RDD with multiple items?

Posted by Nick Pentreath <ni...@gmail.com>.
The function name is flatMap - with capital M to match the Scala API.









—
Sent from Mailbox

On Sun, Dec 13, 2015 at 7:40 PM, Abhishek Shivkumar
<ab...@gmail.com> wrote:

> Hi,
>     I have a RDD of many items.
> Each item has a key and its value is a list of elements.
> I want to unpack the elements of the item so that I can create a new RDD
> with each of its item being the original key and one single element.
> I tried doing RDD.flatmap(lambda line: [ (line[0], v) for v in line[1]])
> but it throws an error saying "AttributeError: 'PipelinedRDD' object has no
> attribute 'flatmap"
> Can someone tell me the right way to unpack the values to different items
> in the new RDD?
> Thank you!
> With Regards,
> Abhishek S