Created
August 2, 2014 15:05
-
-
Save mlehman/69dc9eaa1e254080833c to your computer and use it in GitHub Desktop.
Save Case Class as TSV On Spark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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