hvanhovell commented on code in PR #52271:
URL: https://github.com/apache/spark/pull/52271#discussion_r2330843792


##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/execution/SparkConnectPlanExecution.scala:
##########
@@ -141,19 +143,48 @@ private[execution] class 
SparkConnectPlanExecution(executeHolder: ExecuteHolder)
 
     var numSent = 0
     def sendBatch(bytes: Array[Byte], count: Long, startOffset: Long): Unit = {
-      val response = proto.ExecutePlanResponse
-        .newBuilder()
-        .setSessionId(sessionId)
-        .setServerSideSessionId(sessionHolder.serverSessionId)
+      if (isResultChunkingEnabled) {
+        // Result chunking is enabled. Split the result batch into multiple 
chunks if needed.
+        val maxChunkSize = 
spark.conf.get(CONNECT_SESSION_RESULT_CHUNKING_MAX_CHUNK_SIZE).toInt
+        val numChunks = (bytes.length + maxChunkSize - 1) / maxChunkSize
 
-      val batch = proto.ExecutePlanResponse.ArrowBatch
-        .newBuilder()
-        .setRowCount(count)
-        .setData(ByteString.copyFrom(bytes))
-        .setStartOffset(startOffset)
-        .build()
-      response.setArrowBatch(batch)
-      responseObserver.onNext(response.build())
+        for (i <- 0 until numChunks) {
+          val from = i * maxChunkSize
+          val to = math.min(from + maxChunkSize, bytes.length)
+          val length = to - from
+
+          val response = proto.ExecutePlanResponse

Review Comment:
   You can reuse the builder.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to