Details
Description
map is misused in many places where foreach is intended. This caused a bug in https://issues.apache.org/jira/browse/SPARK-16664 and might be a latent bug elsewhere; it's also easy to find with IJ inspections. Worth patching up.
To illustrate the general problem, map happens to work in Scala where the collection isn't lazy, but will fail to execute the code when it is. map also causes a collection of Unit to be created pointlessly.
scala> val foo = Seq(1,2,3) foo: Seq[Int] = List(1, 2, 3) scala> foo.map(println) 1 2 3 res0: Seq[Unit] = List((), (), ()) scala> foo.view.map(println) res1: scala.collection.SeqView[Unit,Seq[_]] = SeqViewM(...) scala> foo.view.foreach(println) 1 2 3
Attachments
Issue Links
- is cloned by
-
SPARK-34059 Use for/foreach rather than map to make sure execute it eagerly
- Resolved
- links to