fix: bound the batch under the operator that expands a large string scalar #7316
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7316"
general
weight: 0.35
rich7420
Which issue does this PR close?
Part of #7247. The operators that are still unbounded are tracked in #7689.
Rationale for this change
A string scalar, from a scalar subquery or a literal, is expanded to the batch length by aggregates, the hash partitioner and string kernels. A 256 KiB string over the default 8192-row batch needs 2 GiB of value bytes, past Arrow's 32-bit
Utf8offsets, so native execution panics withoffset overflowor fails withbyte array offset overflow. Spark evaluates such scalars row by row and succeeds.The expansion happens in DataFusion (aggregate argument evaluation,
concat) as well as in Comet's shuffle partitioner, and a plan-time fallback cannot see a subquery's value. So the fix bounds the rows per batch that reach the expanding operator.The first version of this PR lowered the session batch size and sliced batches at the scans. Review showed that does not bound what reaches the operator: a filter coalesces its output to its own batch size, a window emits its whole partition, and a scalar built from a subquery result (
repeat(<subquery>, 2)) is wider than the result the planner measured. This version enforces the bound at the operator instead.What changes are included in this PR?
CometBatchSplitExecin the operators crate, a thin operator over DataFusion'sBatchSplitStream, which emits an input batch in slices of at mostbatch_sizerows. Slices share buffers.CometBatchSplitExecwhenever that operator expands a string or binary scalar. The split size is the rows at which the scalars, expanded, reach 1 GiB; for the issue's string that is 4096 rows. A batch at or under that size passes through unsliced, so a scalar of ordinary size never slices anything and never hands a sort zero-copy slices of a shared buffer (apache/datafusion#25804). No width is assumed for what arrives from below, since a filter coalesces toward DataFusion's default, a window emits its whole partition and a broadcast arrives as a few wide batches. A plan without such a scalar is unchanged.Utf8orBinarytype. The planner evaluates it once on a one-row batch, so a scalar built by an expression counts at its final width. A scalar that a comparison (=,<>,<,<=>and the other operators DataFusion evaluates as aDatum) or anINlist takes as a constant is compared and never expanded, so it is skipped:payload = 'x'installs no split. An operand computed per row, such as theINmemberconcat(repeat('x', 262144), CAST(id AS STRING)), counts the scalars it contains. A column, a volatile expression such asuuid(), or a JVM UDF is a per-row node: it is never evaluated at plan time, but the scalars beside it are still counted, soconcat(repeat('x', 262144), uuid())is measured at 256 KiB.executePlanpulls JVM input only when the plan waits for it, as its first call already did, instead of pulling the next batch up front on every call. A limit can then finish on rows a split still holds without reading another batch.ScanExec,ShuffleScanExecand therangesource are unchanged frommain.How are these changes tested?
operators/large_scalar_string.sqlwith fourteen queries that fail onmainwithbyte array offset overflow: the grouped count, the hash partitioning key,concatwith a subquery and with a literal, the literal over a nativerange, a filter under the projection, a window under the aggregate, a 64 KiB scalar over a window partition wider than the session batch size, a scalar besideuuid(),repeatof the subquery result, anINlist with a member computed per row, a sort key under a limit, and a string inside a list scalar expanded byIF. All run inquerymode, so the plan is checked to be native.NullPropagationis excluded so the grouped count keeps its literal argument rather than becomingcount(1).operators/large_scalar_string_small_batch.sqlruns the filter case withspark.comet.batchSize=256, where the scalar fits the session batch size as is.CometExecIteratorLifecycleSuite: a 10-row JVM batch followed by an input that throws, underLIMIT 3, returns three rows without reading the input again. It fails on the loop that pulled JVM input before every poll.CometNativeShuffleSuite: a range shuffle whose ordering expression is a 256 KiB scalar, with no projection between the exchange and therangesource.CometJoinSuite: the deterministic residual test also runs a string residual,concat(CAST(p.payload AS STRING), '!') <> '2506!', and checks the reader filter still attaches and prunes row groups with the split under the filter. Rust unit tests cover the filter keeping its permission through the split and reader attachment crossing it.CometBatchSplitExecand for the scalar measurement: literals and columns, a scalar built by an expression, the strings inside a list, nested list or struct scalar, a scalar beside a volatile sibling that is not evaluated,INlist members, a scalar compared directly against one computed per row, the planner wrapping the input at the scalar's cap whatever the session batch size, and the split going under a sort with a limit but not under a full sort.CometSqlFileTestSuiteforoperators/,scalar_subqueryandshuffle,CometNativeShuffleSuiteandCometJoinSuite, on Spark 4.1, and the core and operators crate test suites.