Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private object SpecialLengths {
val TIMING_DATA = -3
}

private[spark] object PythonRDD {
private[spark] object PythonRDD extends Logging {
val UTF8 = Charset.forName("UTF-8")

def readRDDFromFile(sc: JavaSparkContext, filename: String, parallelism: Int):
Expand Down Expand Up @@ -301,15 +301,23 @@ private[spark] object PythonRDD {
throw new SparkException("Unexpected Tuple2 element type " + pair._1.getClass)
}
case other =>
throw new SparkException("Unexpected element type " + first.getClass)
if (other == null) {
logDebug("Encountered NULL element from iterator. We skip writing NULL to stream.")
} else {
throw new SparkException("Unexpected element type " + first.getClass)
}
}
}
}

def writeUTF(str: String, dataOut: DataOutputStream) {
val bytes = str.getBytes(UTF8)
dataOut.writeInt(bytes.length)
dataOut.write(bytes)
if (str == null) {
logDebug("Encountered NULL string. We skip writing NULL to stream.")
} else {
val bytes = str.getBytes(UTF8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indent is off here (2-space indent)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this one also?

dataOut.writeInt(bytes.length)
dataOut.write(bytes)
}
}

def writeToFile[T](items: java.util.Iterator[T], filename: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ class PythonRDDSuite extends FunSuite {
PythonRDD.writeIteratorToStream(input.iterator, buffer)
}

test("Handle nulls gracefully") {
val input: List[String] = List("a", null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indent is off here (2-space indent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used 4-space indent since other test in this suite had that. I will re-indent to 2-space.

val buffer = new DataOutputStream(new ByteArrayOutputStream)
PythonRDD.writeIteratorToStream(input.iterator, buffer)
}
}