Created
April 7, 2016 23:17
-
-
Save koduki/2b4f3e0127b5899bc497e3aa21910548 to your computer and use it in GitHub Desktop.
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
def saveAsTextFile(path: String): Unit = withScope { | |
// https://issues.apache.org/jira/browse/SPARK-2075 | |
// | |
// NullWritable is a `Comparable` in Hadoop 1.+, so the compiler cannot find an implicit | |
// Ordering for it and will use the default `null`. However, it's a `Comparable[NullWritable]` | |
// in Hadoop 2.+, so the compiler will call the implicit `Ordering.ordered` method to create an | |
// Ordering for `NullWritable`. That's why the compiler will generate different anonymous | |
// classes for `saveAsTextFile` in Hadoop 1.+ and Hadoop 2.+. | |
// | |
// Therefore, here we provide an explicit Ordering `null` to make sure the compiler generate | |
// same bytecodes for `saveAsTextFile`. | |
val nullWritableClassTag = implicitly[ClassTag[NullWritable]] | |
val textClassTag = implicitly[ClassTag[Text]] | |
val r = this.mapPartitions { iter => | |
val text = new Text() | |
iter.map { x => | |
text.set(x.toString) | |
(NullWritable.get(), text) | |
} | |
} | |
RDD.rddToPairRDDFunctions(r)(nullWritableClassTag, textClassTag, null) | |
.saveAsHadoopFile[TextOutputFormat[NullWritable, Text]](path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment