warrenzhu25 opened a new pull request, #7809:
URL: https://github.com/apache/datafusion-comet/pull/7809
**Stacked on #7787.** Until #7787 merges, this branch also carries its
commits. Only the last commit (`fix: return an error instead of panicking when
shuffle strings pass 2 GiB`) is new here. I'll rebase onto `main` and mark this
ready once #7787 lands.
## Which issue does this PR close?
Closes #7803.
## Rationale for this change
#7787 keeps a JVM columnar shuffle batch within Arrow's limits by counting
string rows three times (invalid UTF-8 can triple when `get_string` decodes it)
and splitting encoded blocks past `i32::MAX`. A batch still always takes its
first row, so a single row whose string decodes past 2 GiB, about 716 MiB of
mostly invalid UTF-8, panics with `byte array offset overflow` inside arrow's
`append_value`. A panic that escapes the JNI entry point is undefined behavior.
## What changes are included in this PR?
- `append_string` checks whether a string builder's values would pass
`i32::MAX` bytes before appending and returns arrow's `OffsetOverflowError`
instead of panicking. Every string append goes through it: top-level columns,
struct fields (field-major and row by row), and list and map elements. The
dictionary builder does not expose its values' length, so its arm bounds them
by the bytes appended.
- The append macros take an optional trailing `?`, so only the string
closures return a `Result`; every other type's arm is unchanged.
- `SortedRowEncoder::encode_batch` treats an `OffsetOverflowError`, from an
append or from the cast of a dictionary column back to plain strings, like an
oversized block: for several rows it replaces the builders, which a failed
append leaves part filled, and encodes each half. A single row that cannot fit
fails with an error that says how many bytes its strings take and that invalid
UTF-8 triples when decoded.
- The ×3 row weight from #7787 stays, so the check rarely fires. Removing it
now that an exact check exists would change batch sizes for every string
workload, so that is left for a separate change.
## How are these changes tested?
- `#[ignore]`, need several GiB, run locally with `--ignored`:
- `a_single_row_whose_string_decodes_past_2_gib_fails_cleanly`: one row
with 800 MiB of `0xff` fails with the new error, not a panic, as a top-level
string (plain and dictionary), a struct field, a list element, and a field of a
struct inside a list.
- `invalid_utf8_strings_tripled_past_2_gib_do_not_overflow`: the case from
the #7787 review now also succeeds with the row weight turned off, through the
checked appends and the split, for plain and dictionary strings.
- `blocks_past_i32_max_from_null_structs_are_split` still passes.
- The other `spark_unsafe` tests, and `CometShuffleSuite`,
`DisableAQECometShuffleSuite` and `CometShuffleChecksumDisabledSuite`, pass.
- `sorted_spill` (`benches/row_columnar.rs`, which has a string column)
against #7787's head shows no change beyond noise. An A/A run of the base code
against itself moved by ±4% to 10% on this machine, and two interleaved reruns
of the one case first flagged came out at −3.9% and +4.3%, neither significant.
--
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]