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

   ## Which issue does this PR close?
   
   Part of #7278. Part of #7267.
   
   ## Rationale for this change
   
   `MergeRowsExec` concatenates the output of every matching instruction for an 
input batch into one batch. A split instruction (an update written as a delete 
and an insert) emits two rows per input row, so that batch can hold twice 
`spark.comet.batchSize` rows. With wide string or binary columns, its values 
can also pass Arrow's 2 GiB limit for 32-bit offsets, and the MERGE fails with 
an offset overflow.
   
   This is also the first caller of a shared module for keeping batches within 
Arrow's offsets, as proposed in 
https://github.com/apache/datafusion-comet/issues/7267#issuecomment-7396126763. 
Explode already measured how much of the offset reach a column uses. Other 
operators that copy or combine rows need the same measure and the same ways to 
cut a batch, so they now live in `datafusion-comet-common`.
   
   ## What changes are included in this PR?
   
   - The first commit moves explode's `max_offset_span` into a new 
`offset_limit` module in `datafusion-comet-common`, unchanged.
   - The second commit adds `BatchLimits` (a row limit and an offset limit), 
`split_batch` and `concat_batches_within` to that module.
     - `split_batch` slices a batch without copying. A single row that is too 
wide on its own comes out alone, since it already fits in the array it came 
from.
     - `concat_batches_within` groups consecutive batches that fit within the 
limits and concatenates each group. It checks the limits before concatenating, 
because arrow's `concat` reserves its whole output before it finds that the 
offsets overflow. Dictionary values count toward the limit here, because 
concatenation can copy them. `slice` and `take` leave them shared, so 
`max_offset_span` does not count them.
   - `MergeRowsExec` emits each input batch's output as one or more batches 
within the session batch size and the offset limit. When the output already 
fits in one piece, it is returned without the copy that `concat` used to make.
   
   The aggregate emit half of #7278 is in DataFusion and is not changed here.
   
   ## How are these changes tested?
   
   - Unit tests in `offset_limit.rs` cover spans of sliced, nested and 
dictionary arrays, splitting by rows and by bytes, a row wider than the limit, 
grouping across batches, and empty input. Each uses a limit of a few bytes.
   - In `merge_rows.rs`, `split_output_is_cut_by_batch_size_and_offset_limit` 
checks the batches a split instruction produces under a small row limit and 
offset limit. `stream_returns_every_batch_of_one_input` checks that the stream 
returns every batch produced from one input batch. It fails without this 
change, returning one batch of 6 rows instead of two batches of 3.
   - `CometMergeRowsSuite` runs the Split case at `spark.comet.batchSize=1` on 
Spark 4.1+, and adds a delta-backed split update at a batch size of 1 on Spark 
3.5 and 4.0. Both compare the result with Spark, and the 4.1+ case also 
compares the MERGE counters.
   - The existing explode tests pass unchanged against the moved function.
   


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