Skip to content

fix: End an Arrow chunk before a utf8 or binary array exceeds its 32-bit offsets - #963

Draft
krlmlr wants to merge 9 commits into
claude/rb-arrow-kept-chunkfrom
claude/rb-arrow-byte-limits
Draft

krlmlr wants to merge 9 commits into
claude/rb-arrow-kept-chunkfrom
claude/rb-arrow-byte-limits

Conversation

@krlmlr

@krlmlr krlmlr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

No change of behavior for users: Arrow chunks are still internal. An Arrow chunk now ends before a row whose text or blobs would take a utf8 or binary column beyond the 2^31 - 1 bytes that the 32-bit offsets of these arrays can address, and the next chunk starts with that row. Before, such a chunk failed with an error and ended the result (the limitation accepted as Low on #956). A single text or blob value beyond the limit on its own still fails, with an error that names the column, the size and the limit, but only after the rows before it have come out in the chunks before; it fails the chunk it starts and doesn't loop. This holds also in a column without a declared type that has held only NULL when the limit ends the first chunk, which that chunk fixes as the null type. Later values of such a column that fit become NULL with a warning, as after a first chunk of n rows (the rule from #955).

How: SqliteArrowChunkSink::takes_row() asks each column whether the bytes of the current value fit; a column reads the bytes once for the check and the append. Only what the append adds counts: nothing for NULL, other types or text that a utf8 column makes NULL as invalid UTF-8; numbers count as their text. Reading numbers as text doesn't change their storage class in SQLite, and reading a blob doesn't convert it, so a row that a chunk doesn't take reads alike in the next one; dbColumnInfo() in between doesn't convert values since #951. The row sink's loop leaves the statement on the declined row, so it is neither lost nor read twice; a chunk ended by the limit doesn't read ahead, while a chunk full by n still does and keeps its error. The old draft's arrow_row_read_ and read_type() aren't needed on the row-sink design and aren't ported. The former overflow check in the append is replaced by the check in takes_row() (nanoarrow still refuses an overflowing append).

Tests: the internal result_set_arrow_max_bytes() lowers the limit for a result, so test-arrow-byte-limits.R uses limits of a few bytes: chunks split at the limit with all rows in order for utf8 and binary and for n of -1, 3 and 1; values exactly at and one byte over the limit; several columns with numbers and invalid UTF-8; read-ahead with a kept step error and a kept bind refusal; a declined row keeping its storage class across dbColumnInfo(); a chunk kept by #962 under warn = 2 coming back whole before the declined row; dbBind() after a declined row; an oversized value after NULLs in a column without a declared type, and smaller values in such a column after the cut. The real-size test with blobs near 2 GiB (about 2.5 GB peak resident memory on Linux, with a virtual peak of about 3.1 GB because nanoarrow doubles the capacity of its buffers; platforms whose realloc copies may need more) runs only with RSQLITE_TEST_LARGE_ARROW=true, which the custom after-install action sets on GitHub Actions. Red → green: that test fails on #962's head (c3daa8c) with "Column b: the values of this Arrow chunk would exceed 2^31 - 1 bytes" and passes here. Full suite with NOT_CRAN=true: FAIL 0, WARN 3 (existing encoding tests), SKIP 64, PASS 12631.

Layer F5 of the rebuilt chain, planned in #880; based on #962. Ported from #863.

Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4


https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4


Generated by Claude Code

…bit offsets

The chunk sink's takes_row() asks each column whether the bytes of the current value fit within 2^31 - 1 bytes per utf8 or binary column.
A row that doesn't fit ends the chunk, and the next chunk starts with it.
A value beyond the limit on its own fails the chunk that it starts, after the rows before it.
Before, such a chunk failed with an error and ended the result.

The column reads the bytes once for the check and the append.
Reading numbers as text doesn't change their storage class, and reading a blob doesn't convert it,
so a row that a chunk doesn't take reads alike in the next one.

The internal result_set_arrow_max_bytes() lowers the limit for the tests.
The test with blobs near 2 GiB runs only with RSQLITE_TEST_LARGE_ARROW=true,
which the custom after-install action sets on GitHub Actions.

Ported from #863.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
@krlmlr
krlmlr added this pull request to stack #928 December 1, 2026 07:51
krlmlr and others added 3 commits December 1, 2026 07:58
…umn of NULLs

When the limit ends the first chunk while a column without a declared type has held only NULL,
that chunk fixes the column as the null type.
Text or a blob beyond the limit on its own now fails in such a column too,
after the rows before it, instead of becoming NULL with a warning.
Later values that fit stay NULL, as after a first chunk of `n` rows.

A row that a chunk doesn't take drops the bytes that its columns have read,
and the error names the limit, which a test may have lowered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4

krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Question: should a first chunk that the size limit cuts short fix the type of a column that has only seen NULLs?

This pull request ends an Arrow chunk before a utf8 or binary column would exceed its 32-bit offsets, so a long text column can cut the first chunk short without the user asking for it. A column without a declared type that has only held NULLs up to that cut is then fixed as the null type in finish(), and its later values come back as NULL with a conversion warning. That is the rule #955's question already asks about for a first chunk that n ends, now reachable with n = -1 once 2 GiB of text precede the first value. A single value beyond the limit always fails with a clear error, so only values that fit are affected. Before this pull request, such a fetch failed on the overflow instead. The Arrow stream needs its schema fixed by the first chunk, so the column can't stay open past the cut.

Kirill decides. Until then the first option stays as implemented.


Generated by Claude Code

claude and others added 3 commits December 1, 2026 08:11
… it isn't valid UTF-8

Text or a blob whose bytes alone exceed the limit now always fails,
also in an undecided or utf8 column where text that isn't valid UTF-8 would be NULL.
The reset of the bytes that a column has read happens once, in fits().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants