@@ -1174,6 +1174,14 @@ abstract class RDD[T: ClassTag](
11741174 * Save this RDD as a text file, using string representations of elements.
11751175 */
11761176 def saveAsTextFile (path : String ) {
1177+ // https://issues.apache.org/jira/browse/SPARK-2075
1178+ // NullWritable is a Comparable rather than Comparable[NullWritable] in Hadoop 1.+,
1179+ // so the compiler cannot find an implicit Ordering for it. It will generate different
1180+ // anonymous classes for `saveAsTextFile` in Hadoop 1.+ and Hadoop 2.+. Therefore, here we
1181+ // provide an Ordering for NullWritable so that the compiler will generate same codes.
1182+ implicit val nullWritableOrdering = new Ordering [NullWritable ] {
1183+ override def compare (x : NullWritable , y : NullWritable ): Int = 0
1184+ }
11771185 this .map(x => (NullWritable .get(), new Text (x.toString)))
11781186 .saveAsHadoopFile[TextOutputFormat [NullWritable , Text ]](path)
11791187 }
@@ -1182,6 +1190,10 @@ abstract class RDD[T: ClassTag](
11821190 * Save this RDD as a compressed text file, using string representations of elements.
11831191 */
11841192 def saveAsTextFile (path : String , codec : Class [_ <: CompressionCodec ]) {
1193+ // https://issues.apache.org/jira/browse/SPARK-2075
1194+ implicit val nullWritableOrdering = new Ordering [NullWritable ] {
1195+ override def compare (x : NullWritable , y : NullWritable ): Int = 0
1196+ }
11851197 this .map(x => (NullWritable .get(), new Text (x.toString)))
11861198 .saveAsHadoopFile[TextOutputFormat [NullWritable , Text ]](path, codec)
11871199 }
0 commit comments