HyukjinKwon commented on code in PR #38612:
URL: https://github.com/apache/spark/pull/38612#discussion_r1019838326
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowConverters.scala:
##########
@@ -161,17 +166,23 @@ private[sql] object ArrowConverters extends Logging {
val writeChannel = new WriteChannel(Channels.newChannel(out))
var rowCount = 0L
+ var estimatedBatchSize = arrowSchemaSize
Utils.tryWithSafeFinally {
- while (rowIter.hasNext && (maxRecordsPerBatch <= 0 || rowCount <
maxRecordsPerBatch)) {
+ // Always write the schema.
+ MessageSerializer.serialize(writeChannel, arrowSchema)
+
+ // Always write the first row.
+ while (rowIter.hasNext && (rowCount == 0 || estimatedBatchSize <
maxBatchSize)) {
val row = rowIter.next()
arrowWriter.write(row)
+ estimatedBatchSize += row.asInstanceOf[UnsafeRow].getSizeInBytes
Review Comment:
The size of message should be based on Arrow but we are only able to know
the size of the batch when Arrow batch is created.
So I am fine with the current approach. I do believe that `UnsafeRow` has
bigger size than `ArrowBatch` in general.
One nit would be we should probably set the lower size in `maxBatchSize` to
be conservative. For example, `maxBatchSize * 0.7`
--
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]