The internal Arrow chunks type text columns as utf8 and blob columns as binary,
and a column of NULL values declared as TEXT or BLOB takes that type.
Values of another storage class are read as SQLite converts them:
numbers in a utf8 or binary column are the text that SQLite renders,
text in a binary column is its UTF-8 bytes, and a blob in a utf8 column keeps its bytes.
Text and blobs in an int64 column are their leading integer, or NULL where SQLite would saturate it,
and take their reading as a real when a later real in the first chunk widens the column.
Any value in a column of the null type is NULL.
The conversions stay silent until the conversion reports.
A value that SQLite can't convert for lack of memory fails the chunk,
and so do utf8 or binary values of one chunk beyond the 2^31 - 1 bytes of 32-bit offsets.
Ported from #860, without its UTF-8 checks.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
No change of behavior for users: the Arrow chunks are still fetched only through the unexported
result_fetch_arrow_chunk(). With this pull request they are built from text and blob columns too, which so far failed the chunk with "Arrow arrays of text values are not supported yet."What changes:
SqliteArrowColumntypes a column whose first value that is notNULLis text asutf8, and one whose first such value is a blob asbinary. A column whose values in the first chunk are allNULLtakesutf8for a declared TEXT affinity (TEXT,VARCHAR,CLOB, ...) andbinaryfor BLOB, asdbFetch()types them.utf8orbinarycolumn are the text thatsqlite3_column_text()renders (1.0,1.0e+300,1000000000000000.0, asdbFetch()reads them); text in abinarycolumn is its UTF-8 bytes; a blob in autf8column keeps its bytes; text and blobs in anint64ordoublecolumn are their leading integer or real, as forCAST(), andNULLwhere SQLite would saturate the leading integer, as F1b does for a real beyond the range of int64. In the first chunk, text and blobs that anint64column has read as integers take their reading as a real when a later real widens the column, so the values don't depend on the order of the rows. Any value in a column of the null type isNULL.NULLpointer fromsqlite3_column_text(), or fromsqlite3_column_blob()for a blob of nonzero size) fails the chunk with "Column `x`: out of memory while reading a value.", also on the last row of a full chunk, and completes the result like any other error of a fetch.utf8andbinaryvalues of one chunk that would exceed the 2^31 - 1 bytes of the 32-bit offsets fail the chunk with an error that names the column and the limit, rather than building an invalid array. F5 ends chunks before that limit.Like F1b's own conversions, these are silent until the conversion reports of F4a; the header of
SqliteArrowColumnsays so and the tests pin the values. Left for F2b: checking thatutf8values are valid UTF-8 without NUL bytes, UTF-16 databases, and detecting running out of memory while a blob is read as a number.Tested:
tests/testthat/test-arrow-text.R: text and blob columns with empty strings, zero-length blobs (x'',zeroblob(0)) andNULLamong them, and non-ASCII UTF-8 up to four bytes per character; numbers rendered as text, including the formatting of reals, integers at the limits of int64 and infinity; text and numbers in abinarycolumn and blobs in autf8one; text and blobs inint64anddoublecolumns againstdbFetch()andCAST(x AS REAL), with the saturating cases (spaces, signs, leading zeros, ±2^63); text in anint64column that a later real widens, in three orders of the rows; conversions in a later chunk into all six types; values up to 2 MB; mixed storage classes within and across chunks, with chunk boundaries up to one past the end. Where the rules agree, each chunk is compared withdbFetch()on a separate result in the same chunk sizes, withdbHasCompleted()anddbGetRowCount()after each chunk.tests/testthat/helper-arrow.R:arrow_values()convertsutf8to character andbinaryto blob; the newexpect_valid_chunk()checks every chunk thatexpect_same_chunks()builds: nanoarrow's full validation, which reading the chunk back from the Arrow IPC format runs (nanoarrow 0.6.0 or later), and valid UTF-8 in itsutf8columns.tests/testthat/test-arrow-column-types.R: the tests that expected "not supported yet" now expectNULLfor text and blobs in a column of the null type, andutf8andbinaryfor columns ofNULLvalues declared asVARCHAR,CLOB,TEXTandBLOB, kept by the later chunks.tests/testthat/test-arrow-chunks.R: the test of an error while a chunk is built now runs out of memory under a heap limit, with azeroblob()inbinaryandutf8columns and a large text in a UTF-16 database (the existing helper), and checks that the result is complete; it skips on CRAN.binarycolumn builds, one byte more fails with the new error inbinaryandutf8columns, and the connection works afterwards (gigabytes of memory, so not in the suite).test_that()block of the three Arrow test files passes on its own right afterpkgload::load_all(), apart from two unchanged blocks oftest-arrow-chunks.Rwhoseexpect_snapshot()needs the third edition that the harness didn't set.NOT_CRAN=trueagainst an installed copy: FAIL 0, WARN 3 (localezh_TW.UTF-8not available), SKIP 63, PASS 11870.Questions carried over from #860, for the record: reading text as a real in an open
int64column (#860 (comment)) still applies here, with its cost in time and up to 16 bytes per differing value until the chunk ends. Reporting the conversions (#860 (comment)) still applies, deferred to F4a as in F1b. Naming the column and the limit beyond 2^31 - 1 bytes (#860 (comment)) is settled here: the error names both. Running out of memory while reading a blob as a number (#860 (comment)) moves to F2b with the rest of the out-of-memory handling: here, a blob read into adoubleor openint64column goes throughsqlite3_column_double()without a check.Layer F2a of the rebuilt chain, planned in #880; based on #955. Ported from #860 (draft), without its UTF-8 validation, UTF-16 tests and the out-of-memory refinements that F2b takes.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code