Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save Case Class as TSV On Spark
implicit class ProductRDD[T <: Product](rdd: RDD[T]) {
/* Saves a RDD of Tuples into a TSV.
* Ex: Employee(emp_id = 123, Name(first="Bob",last="Smith")) => "123\tBob\tSmith"
*/
def saveAsTsv(path: String) {
rdd.map(p => p.productIterator.flatMap {
case a: Product => a.productIterator //flattens nested case classes
case b => Seq(b)
}.mkString("\t"))
.saveAsTextFile(path)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.