Skip to content

Instantly share code, notes, and snippets.

@eaorak
Last active Feb 26, 2018
Embed
What would you like to do?
Simple Scala method to print RDD content in Spark
// To be able to easily print RDD content, you can either create a function inside the shell or an implicit class
// Ref to my answer: http://stackoverflow.com/a/41317574/1095213
def p(rdd: org.apache.spark.rdd.RDD[_]) = rdd.foreach(println) // Option 1
implicit class Printer(rdd: org.apache.spark.rdd.RDD[_]) { // Option 2
def print = rdd.foreach(println)
}
// Example
val rdd = sc.parallelize(List(1,2,3,4)).map(_*2)
p(rdd) // 1
rdd.print // 2
// Output
// 2
// 4
// 6
// 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment