You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by "Dai, Kevin" <yu...@ebay.com> on 2014/10/29 04:15:36 UTC

Use RDD like a Iterator

Hi, ALL

I have a RDD[T], can I use it like a iterator.
That means I can compute every element of this RDD lazily.

Best Regards,
Kevin.

RE: Use RDD like a Iterator

Posted by "Ganelin, Ilya" <Il...@capitalone.com>.
Would Rdd.map() do what you need? It will apply a function to every element of the rdd and return a resulting RDD.

-----Original Message-----
From: Zhan Zhang [zzhang@hortonworks.com<ma...@hortonworks.com>]
Sent: Tuesday, October 28, 2014 11:23 PM Eastern Standard Time
To: Dai, Kevin
Cc: user@spark.apache.org
Subject: Re: Use RDD like a Iterator

I think it is already lazily computed, or do you mean something else? Following is the signature of compute in RDD

 def compute(split: Partition, context: TaskContext): Iterator[T]

Thanks.

Zhan Zhang

On Oct 28, 2014, at 8:15 PM, Dai, Kevin <yu...@ebay.com>> wrote:

Hi, ALL

I have a RDD[T], can I use it like a iterator.
That means I can compute every element of this RDD lazily.

Best Regards,
Kevin.


CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to which it is addressed and may contain information that is confidential, privileged and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are hereby notified that any printing, copying, dissemination, distribution, disclosure or forwarding of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and delete it from your system. Thank You.
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.

Re: Use RDD like a Iterator

Posted by Zhan Zhang <zz...@hortonworks.com>.
I think it is already lazily computed, or do you mean something else? Following is the signature of compute in RDD

 def compute(split: Partition, context: TaskContext): Iterator[T]

Thanks.

Zhan Zhang

On Oct 28, 2014, at 8:15 PM, Dai, Kevin <yu...@ebay.com> wrote:

> Hi, ALL
>  
> I have a RDD[T], can I use it like a iterator.
> That means I can compute every element of this RDD lazily.
>  
> Best Regards,
> Kevin.


-- 
CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to 
which it is addressed and may contain information that is confidential, 
privileged and exempt from disclosure under applicable law. If the reader 
of this message is not the intended recipient, you are hereby notified that 
any printing, copying, dissemination, distribution, disclosure or 
forwarding of this communication is strictly prohibited. If you have 
received this communication in error, please contact the sender immediately 
and delete it from your system. Thank You.

Re: Use RDD like a Iterator

Posted by Zhan Zhang <zz...@hortonworks.com>.
RDD.toLocalIterator return the partition one by one but with all elements in the partition, which is not lazy calculated. Given the design of spark, it is very hard to maintain the state of iterator across runJob.

  def toLocalIterator: Iterator[T] = {
    def collectPartition(p: Int): Array[T] = {
      sc.runJob(this, (iter: Iterator[T]) => iter.toArray, Seq(p), allowLocal = false).head
    }
    (0 until partitions.length).iterator.flatMap(i => collectPartition(i))
  }

Thanks.

Zhan Zhang

On Oct 29, 2014, at 3:43 AM, Yanbo Liang <ya...@gmail.com> wrote:

> RDD.toLocalIterator() is the suitable solution.
> But I doubt whether it conform with the design principle of spark and RDD.
> All RDD transform is lazily computed until it end with some actions. 
> 
> 2014-10-29 15:28 GMT+08:00 Sean Owen <so...@cloudera.com>:
> Call RDD.toLocalIterator()?
> 
> https://spark.apache.org/docs/latest/api/java/org/apache/spark/rdd/RDD.html
> 
> On Wed, Oct 29, 2014 at 4:15 AM, Dai, Kevin <yu...@ebay.com> wrote:
> > Hi, ALL
> >
> >
> >
> > I have a RDD[T], can I use it like a iterator.
> >
> > That means I can compute every element of this RDD lazily.
> >
> >
> >
> > Best Regards,
> >
> > Kevin.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
> For additional commands, e-mail: user-help@spark.apache.org
> 
> 


-- 
CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to 
which it is addressed and may contain information that is confidential, 
privileged and exempt from disclosure under applicable law. If the reader 
of this message is not the intended recipient, you are hereby notified that 
any printing, copying, dissemination, distribution, disclosure or 
forwarding of this communication is strictly prohibited. If you have 
received this communication in error, please contact the sender immediately 
and delete it from your system. Thank You.

Re: Use RDD like a Iterator

Posted by Yanbo Liang <ya...@gmail.com>.
RDD.toLocalIterator() is the suitable solution.
But I doubt whether it conform with the design principle of spark and RDD.
All RDD transform is lazily computed until it end with some actions.

2014-10-29 15:28 GMT+08:00 Sean Owen <so...@cloudera.com>:

> Call RDD.toLocalIterator()?
>
> https://spark.apache.org/docs/latest/api/java/org/apache/spark/rdd/RDD.html
>
> On Wed, Oct 29, 2014 at 4:15 AM, Dai, Kevin <yu...@ebay.com> wrote:
> > Hi, ALL
> >
> >
> >
> > I have a RDD[T], can I use it like a iterator.
> >
> > That means I can compute every element of this RDD lazily.
> >
> >
> >
> > Best Regards,
> >
> > Kevin.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
> For additional commands, e-mail: user-help@spark.apache.org
>
>

Re: Use RDD like a Iterator

Posted by Sean Owen <so...@cloudera.com>.
Call RDD.toLocalIterator()?

https://spark.apache.org/docs/latest/api/java/org/apache/spark/rdd/RDD.html

On Wed, Oct 29, 2014 at 4:15 AM, Dai, Kevin <yu...@ebay.com> wrote:
> Hi, ALL
>
>
>
> I have a RDD[T], can I use it like a iterator.
>
> That means I can compute every element of this RDD lazily.
>
>
>
> Best Regards,
>
> Kevin.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org