warrenzhu25 opened a new pull request, #7787:
URL: https://github.com/apache/datafusion-comet/pull/7787

   ## Which issue does this PR close?
   
   Closes #7497. Part of #7267.
   
   ## Rationale for this change
   
   The JVM columnar shuffle converts sorted UnsafeRows to Arrow in batches of
   `spark.comet.shuffle.jvm.batchSize` rows (capped by `spark.comet.batchSize`).
   Both entry points, `process_sorted_row_partition` and the sort-based
   `process_sorted_partitions`, cut batches by row count only. Arrow indexes a
   string or binary column's values with i32 offsets, so once one column of one
   batch passes 2 GiB (about 256 KiB per value at 8192 rows) the task panics 
with
   `byte array offset overflow`, or fails with `OffsetOverflowError` when a
   dictionary column falls back to plain values. Spark shuffles rows and has no
   batch to overflow, so the same query succeeds without Comet. The only
   workaround was lowering the batch size for every shuffle.
   
   ## What changes are included in this PR?
   
   - `batch_has_room` ends a batch at the row limit or before the sum of its
     UnsafeRow sizes passes `MAX_BATCH_ROW_BYTES`, whichever comes first. A 
batch
     always takes its first row, which is at most i32::MAX bytes.
   - Both entry points use it: the row-partition path reads the sizes Spark
     passes in, and the sort-based path checks each row as it resolves the
     record pointer.
   - A row's size bounds the bytes it adds to any one column, including strings
     nested in arrays, maps and structs, so the cut needs no look at the values.
   - The budget is 1 GiB rather than i32::MAX. The JVM reader
     (`NativeBatchDecoderIterator`) rejects a whole block past
     `Integer.MAX_VALUE` bytes, and an uncompressed or incompressible block 
built
     from close to 2 GiB of rows could reach that. Batches under 1 GiB of rows,
     which is nearly all data, are cut exactly as before.
   - The budget is passed to private `*_within` functions so tests can inject a
     small one. The public signatures and the JNI call sites are unchanged.
   
   ## How are these changes tested?
   
   - `batch_has_room_takes_the_first_row_then_respects_both_limits`: the first
     row is always taken, the byte limit is inclusive, and the row limit holds.
   - `sorted_row_partition_ends_batches_at_the_byte_budget`: writes real rows
     through `process_sorted_row_partition` for six batch-size and budget
     combinations, including a budget below one row, and checks the number of
     blocks written and that the strings read back unchanged and in order.
   - `sorted_partitions_end_batches_at_the_byte_budget`: lays records out in a
     page as Spark's sorter stores them, across two partitions and an empty one,
     and checks the blocks per partition, that `partition_lengths` matches the
     file, and the round-tripped strings.
   - Existing `CometShuffleSuite`, `DisableAQECometShuffleSuite` and
     `CometShuffleChecksumDisabledSuite` pass.
   


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

Reply via email to