[ 
https://issues.apache.org/jira/browse/SPARK-28854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16915111#comment-16915111
 ] 

Hyukjin Kwon commented on SPARK-28854:
--------------------------------------

No, this is not a bug. You're trying to consume an iterator that was already 
consumed:

{code}
scala> val xs = Iterator(1, 2, 3)
xs: Iterator[Int] = <iterator>

scala> xs.map(2*).zip(xs).toArray
warning: there was one feature warning; for details, enable `:setting -feature' 
or `:replay -feature'
java.util.NoSuchElementException: next on empty iterator
  at scala.collection.Iterator$$anon$2.next(Iterator.scala:41)
  at scala.collection.Iterator$$anon$2.next(Iterator.scala:39)
  at scala.collection.IndexedSeqLike$Elements.next(IndexedSeqLike.scala:63)
  at scala.collection.Iterator$$anon$18.next(Iterator.scala:849)
{code}

> Zipping iterators in mapPartitions will fail
> --------------------------------------------
>
>                 Key: SPARK-28854
>                 URL: https://issues.apache.org/jira/browse/SPARK-28854
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Core
>    Affects Versions: 2.4.3
>            Reporter: Hao Yang Ang
>            Priority: Minor
>
> {code}
> scala> sc.parallelize(Seq(1, 2, 3)).mapPartitions(xs => 
> xs.map(2*).zip(xs)).collect.foreach(println)
> ...
> java.util.NoSuchElementException: next on empty iterator
> {code}
>  
>  
> Workaround - implement zip with mapping to tuple:
> {code}
> scala> sc.parallelize(Seq(1, 2, 3)).mapPartitions(xs => xs.map(x => (x * 2, 
> x))).collect.foreach(println)
> (2,1)
> (4,2)
> (6,3)
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to