Added foreachPartition method to JavaRDD.

This commit is contained in:
eklavya 2014-01-13 17:56:47 +05:30
parent dbadc6b994
commit 6a65feebc7

View file

@ -21,7 +21,7 @@ import scala.reflect.ClassTag
import org.apache.spark._
import org.apache.spark.rdd.RDD
import org.apache.spark.api.java.function.{Function => JFunction, FlatMapFunction => JFMap}
import org.apache.spark.api.java.function.{Function => JFunction, FlatMapFunction => JFMap, VoidFunction}
import org.apache.spark.storage.StorageLevel
import java.util.{Iterator => JIterator}
import scala.collection.JavaConversions._
@ -149,6 +149,13 @@ JavaRDDLike[T, JavaRDD[T]] {
rdd.mapPartitions[U]((x => f(asJavaIterator(x)).iterator), preservesPartitioning)
}
/**
* Applies a function f to each partition of this RDD.
*/
def foreachPartition(f: VoidFunction[JIterator[T]]) {
rdd.foreachPartition((x => f(asJavaIterator(x))))
}
}
object JavaRDD {