sunchao commented on a change in pull request #35613:
URL: https://github.com/apache/spark/pull/35613#discussion_r812532597
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala
##########
@@ -384,17 +385,32 @@ abstract class SparkPlan extends QueryPlan[SparkPlan]
with Logging with Serializ
val bis = new ByteArrayInputStream(bytes)
val ins = new DataInputStream(codec.compressedInputStream(bis))
- new Iterator[InternalRow] {
+ new NextIterator[InternalRow] {
+ Option(TaskContext.get()).foreach(_.addTaskCompletionListener[Unit](_ =>
closeIfNeeded()))
private var sizeOfNextRow = ins.readInt()
- override def hasNext: Boolean = sizeOfNextRow >= 0
- override def next(): InternalRow = {
- val bs = new Array[Byte](sizeOfNextRow)
- ins.readFully(bs)
Review comment:
We can't close it here since we'll need to read multiple rows from the
input stream, one for each `next` call, and only close when done processing the
iterator.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala
##########
@@ -384,17 +385,32 @@ abstract class SparkPlan extends QueryPlan[SparkPlan]
with Logging with Serializ
val bis = new ByteArrayInputStream(bytes)
val ins = new DataInputStream(codec.compressedInputStream(bis))
- new Iterator[InternalRow] {
+ new NextIterator[InternalRow] {
+ Option(TaskContext.get()).foreach(_.addTaskCompletionListener[Unit](_ =>
closeIfNeeded()))
Review comment:
Yea we can't use `TaskContext` here: seems we need to find some other
way to close the input stream.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala
##########
@@ -384,17 +385,32 @@ abstract class SparkPlan extends QueryPlan[SparkPlan]
with Logging with Serializ
val bis = new ByteArrayInputStream(bytes)
val ins = new DataInputStream(codec.compressedInputStream(bis))
- new Iterator[InternalRow] {
+ new NextIterator[InternalRow] {
+ Option(TaskContext.get()).foreach(_.addTaskCompletionListener[Unit](_ =>
closeIfNeeded()))
private var sizeOfNextRow = ins.readInt()
- override def hasNext: Boolean = sizeOfNextRow >= 0
- override def next(): InternalRow = {
- val bs = new Array[Byte](sizeOfNextRow)
- ins.readFully(bs)
- val row = new UnsafeRow(nFields)
- row.pointTo(bs, sizeOfNextRow)
- sizeOfNextRow = ins.readInt()
- row
+ override def getNext(): InternalRow = {
+ if (sizeOfNextRow >= 0) {
+ try {
+ val bs = new Array[Byte](sizeOfNextRow)
+ ins.readFully(bs)
+ val row = new UnsafeRow(nFields)
+ row.pointTo(bs, sizeOfNextRow)
+ sizeOfNextRow = ins.readInt()
+ row
+ } catch {
+ case e: Exception =>
Review comment:
+1. It's safer to catch on `Throwable`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]