viirya commented on code in PR #50080:
URL: https://github.com/apache/spark/pull/50080#discussion_r1971070779


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/PythonArrowInput.scala:
##########
@@ -140,3 +141,53 @@ private[python] trait BasicPythonArrowInput extends 
PythonArrowInput[Iterator[In
     }
   }
 }
+
+
+private[python] trait BatchedPythonArrowInput extends BasicPythonArrowInput {
+  self: BasePythonRunner[Iterator[InternalRow], _] =>
+  private val arrowMaxRecordsPerBatch = SQLConf.get.arrowMaxRecordsPerBatch
+
+  private val maxBytesPerBatch = SQLConf.get.arrowMaxBytesPerBatch
+
+  // Marker inside the input iterator to indicate the start of the next batch.
+  private var nextBatchStart: Iterator[InternalRow] = Iterator.empty
+
+  override protected def writeNextBatchToArrowStream(
+      root: VectorSchemaRoot,
+      writer: ArrowStreamWriter,
+      dataOut: DataOutputStream,
+      inputIterator: Iterator[Iterator[InternalRow]]): Boolean = {
+    if (!nextBatchStart.hasNext) {
+      if (inputIterator.hasNext) {
+        nextBatchStart = inputIterator.next()
+      }
+    }
+    if (nextBatchStart.hasNext) {
+      val startData = dataOut.size()
+
+      var numRowsInBatch: Int = 0
+
+      def underBatchSizeLimit: Boolean =
+        (maxBytesPerBatch == Int.MaxValue) || (arrowWriter.sizeInBytes() < 
maxBytesPerBatch)

Review Comment:
   Due to the API issue 
https://github.com/apache/spark/pull/50080/files#r1971063958
   
   Maybe we can call `ArrowWriter.bytesWritten` 
(https://arrow.apache.org/docs/dev/java/reference/org/apache/arrow/vector/ipc/ArrowWriter.html#bytesWritten())?



-- 
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