Skip to content

fix: return an error instead of aborting in repeat for huge LargeUtf8 results - #26957

Open
shahwazreza wants to merge 2 commits into
apache:mainfrom
shahwazreza:fix-repeat-large-utf8-abort
Open

shahwazreza wants to merge 2 commits into
apache:mainfrom
shahwazreza:fix-repeat-large-utf8-abort

Conversation

@shahwazreza

@shahwazreza shahwazreza commented Oct 30, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

repeat on a LargeUtf8 string with a huge count, e.g. repeat(arrow_cast('a', 'LargeUtf8'), 1152921504606846976), aborts the process (scalar case) or panics (array case) instead of returning an error. Utf8 and Utf8View already error above i32::MAX bytes, but LargeUtf8 was capped at i64::MAX, which is way past anything that can actually be allocated.

What changes are included in this PR?

LargeUtf8 now uses a fixed cap of u32::MAX bytes (LARGE_UTF8_MAX_SIZE). In the array path the cap applies to each value and to the total size of the output, since the builder allocates the whole output up front. My first version only checked each value, so lots of rows could still add up to an allocation that panics. The second commit fixes that.

The issue asked whether to use a cap or fallible allocation. I went with a cap because the builder has no fallible way to allocate, and changing that would be a bigger separate change. A cap also behaves the same way Utf8 already does.

u32::MAX matches DuckDB's string size limit and still lets LargeUtf8 go past the Utf8 limit. Happy to change it, e.g. to Postgres' 1 GB, if it is preferred.

This doesn't help when an allocation under the cap succeeds and then fails later because of overcommit, same as the issue says.

What is the testing strategy for this PR?

Unit tests in repeat.rs:

  • scalar LargeUtf8 with a count of 1 << 60 (used to abort the test process)
  • array LargeUtf8 with a count of 1 << 60 (used to panic)
  • array with two rows of ~3 GB each: fine on their own, over the cap together

Are there any user-facing changes?

repeat returns an error for LargeUtf8 results over u32::MAX bytes instead of trying to allocate them.

…f8 results

`repeat` capped LargeUtf8 results at i64::MAX bytes, which admits sizes
no allocation can satisfy, so the process aborted or panicked instead of
returning an error. Cap LargeUtf8 results at u32::MAX bytes in both the
scalar and array paths.

Closes apache#26948
@github-actions github-actions Bot added the functions Changes to functions implementation label Oct 30, 2026
The per-row cap alone still let many rows add up to an allocation no
system can satisfy, which panicked in the Arrow buffer instead of
returning an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repeat on LargeUtf8 aborts the process on a result size no allocation can satisfy

1 participant