HyukjinKwon commented on code in PR #38613:
URL: https://github.com/apache/spark/pull/38613#discussion_r1019833127
##########
connector/connect/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectStreamHandler.scala:
##########
@@ -184,9 +158,30 @@ class SparkConnectStreamHandler(responseObserver:
StreamObserver[Response]) exte
responseObserver.onNext(response.build())
numSent += 1
}
+ }
+
+ // Store collection results for worst case of 1 to N-1 partitions
+ val results = new Array[Array[Batch]](numPartitions - 1)
+ var lastIndex = -1 // index of last partition written
- currentPartitionId += 1
+ // Handler to eagerly write partitions in order
+ val resultHandler = (partitionId: Int, partition: Array[Batch]) => {
+ // If result is from next partition in order
+ if (partitionId - 1 == lastIndex) {
+ writeBatches(partition)
+ lastIndex += 1
+ // Write stored partitions that come next in order
+ while (lastIndex < results.length && results(lastIndex) != null) {
+ writeBatches(results(lastIndex))
+ results(lastIndex) = null
+ lastIndex += 1
+ }
+ } else {
+ // Store partitions received out of order
+ results(partitionId - 1) = partition
+ }
}
+ spark.sparkContext.runJob(batches, (iter: Iterator[Batch]) =>
iter.toArray, resultHandler)
Review Comment:
Hm, I just noticed the review comment. I believe this is matched with our
current implementation in PySpark. If we should improve, let's improve both
paths together. I would prefer to match them and deduplicate the logic first.
--
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]