Skip to content

Commit eb82abd

Browse files
committed
[SPARK-2529] Clean closures in foreach and foreachPartition.
Author: Reynold Xin <[email protected]> Closes #1583 from rxin/closureClean and squashes the following commits: 8982fe6 [Reynold Xin] [SPARK-2529] Clean closures in foreach and foreachPartition.
1 parent 8529ced commit eb82abd

File tree

1 file changed

+4
-2
lines changed
  • core/src/main/scala/org/apache/spark/rdd

1 file changed

+4
-2
lines changed

core/src/main/scala/org/apache/spark/rdd/RDD.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,16 @@ abstract class RDD[T: ClassTag](
754754
* Applies a function f to all elements of this RDD.
755755
*/
756756
def foreach(f: T => Unit) {
757-
sc.runJob(this, (iter: Iterator[T]) => iter.foreach(f))
757+
val cleanF = sc.clean(f)
758+
sc.runJob(this, (iter: Iterator[T]) => iter.foreach(cleanF))
758759
}
759760

760761
/**
761762
* Applies a function f to each partition of this RDD.
762763
*/
763764
def foreachPartition(f: Iterator[T] => Unit) {
764-
sc.runJob(this, (iter: Iterator[T]) => f(iter))
765+
val cleanF = sc.clean(f)
766+
sc.runJob(this, (iter: Iterator[T]) => cleanF(iter))
765767
}
766768

767769
/**

0 commit comments

Comments
 (0)