fix: bound native explode output batch size - #5559
Closed
sam-1112 wants to merge 3 commits into
Closed
Conversation
comphead
reviewed
Aug 30, 2026
comphead
left a comment
Contributor
There was a problem hiding this comment.
Thanks @sam-1112
@andygrove cc I think it was fixed in DF 55.1?
Member
Yes, it is. We also already have an approved PR to fix this in Comet #5362 |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Related to #5409 and #5354.
Rationale for this change
DataFusion 54.1.0's
UnnestExeccan emit batches containing more rows thanspark.comet.batchSize. This violates the runtime batch-size boundary expected by downstream native operators. In particular, a downstream projection that broadcasts a scalar into an ArrowUtf8array can overflow its 32-bit offsets.This PR wraps native
UnnestExecwithBatchSplitExec, which splits oversized output batches according to the runtimeTaskContextbatch size before passing them downstream.This is a temporary workaround until Comet upgrades to a DataFusion version containing datafusion#24384. The change was split out of #5409 so that the broader explode runtime behavior can be reviewed independently.
What changes are included in this PR?
BatchSplitExecafter nativeUnnestExec.UnnestExecmetrics through the wrapper.batches_splitonCometExplodeExec. DataFusion increments this counter once for each output slice produced from an oversized input batch.output_batchesas the originalUnnestExecoutput-batch count from before splitting, rather than changing the meaning of the existing metric.Limitations
UnnestExecconstructs the expanded batch.elapsed_computeremains theUnnestExeccompute time and does not include the wrapper's slicing cost.batches_splitexposes split activity, but not the time spent slicing.Performance
Measured using a release native build (
-Ctarget-cpu=native) with 5 warm-up runs and 10 measured runs. Values below are medians in ns per input row.Environment:
src=spark.range(131072),spark.sql.leafNodeDefaultParallelism=1SELECT explode(array(id)) AS e FROM src(array size 1)SELECT explode(array(id, id)) AS e FROM src(array size 2)spark.comet.batchSize: 8192076c092a4. Later commitdb10f73dbdoes not change the explode execution path.Both arms used the same source revision and release build settings. For the without-wrapper arm, the planner was changed locally to return the original
UnnestExecdirectly; no other code was changed.The observed no-split pass-through overhead was approximately 6 ns per input row (about 1.5%). The split arm was 43 ns per input row faster in this end-to-end measurement, possibly because downstream
collect()received smaller batches. This result does not establish that splitting itself improves performance. No regression was observed in this workload.How are these changes tested?
The Rust unit test verifies that:
[4, 4, 2];output_rowsmetric is forwarded; andbatches_split == 3.The Spark integration test verifies that:
explode;CometExplodeExec;input_rows == 16;output_rows == 32; andbatches_split > 0is exposed through the Spark SQL metric map.