liupc commented on a change in pull request #23799: [SPARK-26892][CORE] Fix
saveAsTextFile throws NullPointerException when null row present
URL: https://github.com/apache/spark/pull/23799#discussion_r258464604
##########
File path: core/src/main/scala/org/apache/spark/rdd/RDD.scala
##########
@@ -1492,45 +1492,21 @@ abstract class RDD[T: ClassTag](
* Save this RDD as a text file, using string representations of elements.
*/
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)
+ saveAsTextFile(path, null)
}
/**
* Save this RDD as a compressed text file, using string representations of
elements.
*/
def saveAsTextFile(path: String, codec: Class[_ <: CompressionCodec]): Unit
= withScope {
- // https://issues.apache.org/jira/browse/SPARK-2075
- val nullWritableClassTag = implicitly[ClassTag[NullWritable]]
- val textClassTag = implicitly[ClassTag[Text]]
val r = this.mapPartitions { iter =>
Review comment:
Done, thank you @srowen
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]