Skip to content

feat: Convert data frames column by column, with lazy_strings as an option - #807

Closed
krlmlr wants to merge 28 commits into
claude/elegant-tesla-mja103-ptypefrom
claude/elegant-tesla-mja103-lazy
Closed

krlmlr wants to merge 28 commits into
claude/elegant-tesla-mja103-ptypefrom
claude/elegant-tesla-mja103-lazy

Conversation

@krlmlr

@krlmlr krlmlr commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Stacked on #802 (base branch claude/elegant-tesla-mja103-ptype), which is stacked on #801, #800, #796 and #795. #831 sits on top of this one and declares the DBItest version.

dbConnect(arrow = TRUE, lazy_strings = TRUE) opts into leaving the character columns of fetched data frames as nanoarrow's views into Arrow arrays instead of copying the strings out. No ALTREP class of RSQLite's own: the views are nanoarrow's, and the cost they carry today is to be taken upstream. Default FALSE.

Conversion. This layer changes only fetches with a lazy column. Every other fetch, including every fetch without lazy_strings, keeps the conversion of the layers below unchanged: one array is converted at once, and several arrays go through the R-level copy loop of #796, which releases each array as soon as it is copied. Converting eager fetches column by column as well took as long and peaked higher, because nanoarrow::convert_array_stream() keeps its arrays until the next garbage collection; the experiment README records that comparison. A fetch with a lazy column and at least one array is split by column in C++ (arrow_split_columns()), which moves the children of its struct arrays into one stream per column, so that a view holds the strings of its own column alone. arrow_lazy_columns() then replaces only the conversion step of arrow_to_df(). The lazy columns are concatenated, and nanoarrow fills each of the other columns in one vector with the prototype as its target. Factors, times in seconds, the prototypes' attributes, the narrowing of integers, bigint and the coercion warning, raised after the conversion, follow as for every other fetch.

lazy_strings. A character column without a prototype, or with a plain character() one, is concatenated into one array in C++ (arrow_concat_strings()). It hands a single array on as it is, frees each chunk once copied, and builds large_utf8 when the strings need more than the 2^31 - 1 bytes that utf8 offsets address. Factors, blobs and any column with another prototype stay eager, and factors without levels are built from copies. All arrays of a lazy fetch count towards the young-generation collection that dbFetchArrowChunk() already triggers every 64 MB, since the collector does not see their memory. The option requires arrow = TRUE, is validated and cloned like arrow, and is documented in ?SQLite and in the "Data frames" section of ?"sqlite-arrow", including its price: most vectorised uses of a view convert its strings again, one by one, so a column used more than once is better copied with c() first.

Tests. tests/testthat/test-DBItest-arrow.R and the new test-DBItest-arrow-lazy.R share a helper, helper-DBItest-arrow.R, that builds the context and runs the groups that fetch or write data frames: test_driver(), which checks bigint with dbGetQuery(), plus test_result(), test_sql(), test_meta(), test_transaction() and test_arrow(). The getting started, connection, compliance and stress groups call nothing on this path. With DBItest 1.8.3, the eager and the lazy contexts each pass 8033 expectations with the same 59 skipped tests. This layer keeps dbitest_version = "1.8.1" as the layers below do, and #831 declares the newer version. tests/testthat/test-arrow-lazy.R covers:

  • validation and cloning of the option;
  • equality with the eager data frames across full fetches, chunks, empty tails and zero rows;
  • views that outlive the result, the connection and a garbage collection;
  • prototypes of every kind, converted from one array and from one array per row;
  • times in seconds and the coercion warning;
  • the collection trigger;
  • large_utf8 with a lowered limit;
  • with RSQLITE_TEST_LARGE_ARROW=true (about 2.5 GB of memory, with chunks cut at 64 MiB and garbage collected before and after), a text column of 2049 MiB.

Benchmark. experiments/2026-09-26-arrow-df-fetch/ gains a run on fbd54c9, whose R and C++ code is that of this head. The harness now reads the peak RSS before object.size(), which had added up to 170 MB to the cells with text. Five million rows, medians of two repetitions, on an Ubuntu 24.04 container with 4 cores of an Intel Xeon at 2.1 GHz, R 4.5.3, SQLite 3.54.1 and nanoarrow 0.9.0. Timings move by about 10 % between repetitions on this shared machine, and the peak RSS repeats to the MB.

  • All columns, full fetch:
    • lazy strings: 3.6 s and 642 MB above the floor;
    • eager: 9.4 s and 730 MB, which is the conversion of the layers below;
    • default path: 15.7 s and 614 MB.
  • The strings alone: 2.0 s lazy, 7.5 s eager and 11.6 s on the default path.
  • A loop of dbFetch(n = 10000) that discards its data frames: 3.3 s and 159 MB lazy, 6.8 s and 133 MB eager.
  • Numbers-only cells do not move.
  • Small fetches cost more, measured separately on 100,000 rows of five columns, three repetitions. Per fetch of 10 rows: 0.26 to 0.36 ms lazy, 0.17 to 0.21 ms eager, 0.06 ms on the default path. Per fetch of 100 rows: 0.29 to 0.37, 0.19 to 0.25 and 0.12 to 0.16 ms. From 1,000 rows on, the three are within noise.

Review

A clean-context review (2026-09-27) found one High issue (lazy strings beyond 2 GiB per column failed the fetch), one Medium (the driver and transaction specs were missing from the Arrow DBItest runs) and one Low (dead code). All are fixed after merging the final versions of the layers below. Its suggestion to declare a newer dbitest_version is taken up in #831. The integration review of the whole stack at 071560e found no issue in this layer's code. It compared lazy and eager data frames on 3,000 random tables, with and without ptype and with two-row chunks, ran the tests under AddressSanitizer, and ran gctorture() around the split and the concatenation. Its note that this description had fallen behind the code is addressed here.

What remains is listed under Accepted limitations.

The test fixtures this pull request adds live in tests/testthat/helper-arrow.R, so every test_that() block runs on its own right after load_all(). is_lazy() is named is_lazy_strings() there.

https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE


Generated by Claude Code

… option

The data frame path through Arrow now hands each column to R on its own:
a fetch of all rows reads the result into chunks first and splits them by column,
so that each column is allocated once with the row count known
and its arrays are freed as soon as it is converted,
and a fetch of `n` rows converts its chunk column by column the same way.

`dbConnect(arrow = TRUE, lazy_strings = TRUE)` opts into leaving character columns
as nanoarrow's views into their Arrow arrays instead of copying the strings out:
a view holds the strings in less memory than R does and goes when the column is dropped,
while the other columns are converted and freed at once.
For a fetch of all rows, the chunks of a character column are concatenated into one array in C++.
Until nanoarrow caches the strings of a view, every vectorised use converts the column again,
which the documentation says, and which keeps the option off by default.

The DBItest runs for the Arrow data frame path are limited to the groups that fetch or write
data frames, and a third run covers the option.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6
`object.size()` reads every string of a data frame,
which materializes a column that `lazy_strings = TRUE` left as a view
and charged the conversion to the fetch it was meant to describe.
The harness also gains the two lazy strategies,
which it skips on a build without the option.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6

krlmlr commented Sep 27, 2026

Copy link
Copy Markdown
Member Author

Review of this PR at fe6e409, by a Claude Code reviewer with clean context that read the diff against claude/elegant-tesla-mja103-ptype, ran targeted R snippets against the installed build of this branch, and posted nothing itself. Line numbers refer to that commit. "Confirmed" means reproduced by running code. Two items come from a second reviewer of the merged r-dbi/DBItest#571.

High

1. lazy_strings = TRUE concatenates every chunk of a text column into one utf8 array with 32-bit offsets, so a column totalling more than 2 GiB fails the whole fetch where the eager path succeeds. arrow_concat_strings() in src/result.cpp:241-321 keeps the chunk's type at line 272. Confirmed: 3072 rows of 1 MiB strings, three chunks of about 1 GiB, fail dbGetQuery() with arrow = TRUE, lazy_strings = TRUE with Can't append to Arrow array, and return 3072 rows with lazy_strings = FALSE. Suggested fix: the chunks are all in memory, so sum their data sizes first and build large_utf8 when the total exceeds INT32_MAX (nanoarrow's ALTREP view supports large strings), or fall back to eager conversion for that column.

Medium

2. Restricting the arrow = TRUE DBItest runs drops transaction coverage of the Arrow data frame path. tests/testthat/helper-DBItest-arrow.R:31-34 runs only test_result(), test_sql(), test_meta() and test_arrow(), and the description says the transaction, driver, connection, compliance and stress groups never touch the path. Deparsing DBItest 1.8.3 shows spec_transaction_begin_commit_rollback, spec_transaction_with_transaction and spec_driver_connect calling dbWriteTable(), dbReadTable() and dbGetQuery(); savepoints around dbAppendTableArrow() under an outer transaction are exactly what those specs exercise. Suggested fix: add test_transaction() and test_driver() to the helper, or keep test_all() for one of the two contexts.

Low

3. Dead code after the column-stream rewrite. result_fetch_arrow_all() (src/result.cpp:117-142) and db_arrow_buffered_stream_init() (src/DbArrowStream.cpp:192-217, declared in the header) have no R caller any more, and the wrapper in R/cpp11.R remains.

4. "Freed as soon as converted" is one garbage collection later for the eager columns that nanoarrow::convert_array_stream() fills, since the converter only swaps the previous batch out of its shelter. Informational; the benchmark's peak-RSS numbers stand.

From the review of r-dbi/DBItest#571

5. Declare dbitest_version = "1.8.3.6" in tests/testthat/helper-DBItest.R. The six new schema specs of that PR pass on this branch's native path and on CRAN RSQLite, and DBItest's own tests/testthat/test-DBItest.R is generated from this helper, so the bump is what puts the specs into DBItest's CI. tweaks() does not validate the value, so it is harmless with an older installed DBItest.

6. ARROW_ROUNDTRIP_SKIPS is unconditional, and the helper is copied verbatim into DBItest's and DBI's own test files, where CRAN RSQLite passes those twelve specs. Copied as is, the list would switch them off there. Guard it on the native Arrow path being present (a version check or the presence of the native dbFetchArrow() method), or resolve it on the DBItest side (r-dbi/DBItest#334, strict bigint against expect_identical()).

Checked and found sound

  • Moving the children out of the nanoarrow struct is safe: its release skips children with release == NULL; the schemas are deep-copied per column and every column pointer is independent.
  • The ALTREP views keep their array alive through nanoarrow's converter, nothing in RSQLite releases an array that backs a view, and a view outlives the result and the connection (test and run).
  • test-arrow-lazy.R and the other five Arrow test files pass on the installed build.

Generated by Claude Code

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The findings of the clean-context review, placed on the code they concern; the summary comment above carries the full report, the two items carried over from the review of r-dbi/DBItest#571, and the checks that came out sound. Line positions refer to the current head, with the stack below and main merged in.


Generated by Claude Code

Comment thread src/result.cpp Resolved
Comment thread tests/testthat/helper-DBItest-arrow.R Resolved
Comment thread src/result.cpp Resolved
Comment thread R/arrow.R Resolved
…tesla-mja103-lazy

The layers below now type every data frame fetch in C++ and hand it to R as one stream from `result_fetch_arrow_df()`, for fetches of `n` rows and of all rows alike.
This branch's own fetch functions, `result_fetch_arrow_columns()` and `result_fetch_arrow_chunk_columns()`, bypassed that typing and are gone, with `db_arrow_column_streams_init()`.
The column-by-column conversion now starts from that stream: `arrow_split_columns()` moves the children of its arrays into one buffered stream per column, which nanoarrow converts with the row count known.
A fetch that fits into one array keeps the conversion of the layers below unless a column stays lazy.
The prototype stays the conversion target of every column, its attributes are put back after the fill, and factors without levels are still built after the conversion, eagerly.
With `lazy_strings`, a character column without a prototype or with a plain `character()` one is concatenated into one array by `arrow_concat_strings()`, which now also returns the bytes it holds for the collection trigger of every fetch.
`result_fetch_arrow_all()` was already removed below, and `db_arrow_buffered_stream_init()` serves both the layers below and the split.
The data frames section of `?sqlite-arrow` says where arrays are released and where the garbage collector frees them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
With `lazy_strings = TRUE`, the chunks of a text column were copied into one `utf8` array, whose 32-bit offsets address at most 2^31 - 1 bytes.
A column with more text than that failed the whole fetch with "Can't append to Arrow array", where the eager path succeeds.
`arrow_concat_strings()` now takes all arrays of the column first, sums the bytes of their strings, and builds a `large_utf8` array when they exceed that limit.
It reserves the buffers up front, so that the copy no longer grows them, and hands a single array on as it is.
The internal `arrow_set_concat_utf8_max_bytes()` lowers the limit for the tests, and a test of 2100 strings of 1 MiB runs with `RSQLITE_TEST_LARGE_ARROW=true`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A result with a prototype for every kind of column, from time zones and factor levels to `blob`, `hms` and `integer64`, gives the same data frame converted from one array at once as converted column by column, eagerly and with `lazy_strings = TRUE`.
Only the character columns stay views, factors without levels are built from copies, and the eager path keeps no view.
The bytes of a lazy column count towards the collection that `dbFetchArrowChunk()` triggers, in every fetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The DBItest contexts with `arrow = TRUE` ran only the result, SQL, meta and Arrow groups.
The driver group checks `bigint` with `dbGetQuery()`, and the transaction group writes and reads tables inside transactions, where `dbAppendTableArrow()` takes savepoints under the outer transaction.
Both now run in the eager and in the lazy context, and pass there.
The getting started, connection, compliance and stress groups call no function of the data frame path and stay out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
DBItest gates the six specs for requested Arrow schemas behind `dbitest_version` 1.8.3.1 to 1.8.3.6, and its own CI runs RSQLite with the context of `helper-DBItest.R`.
With the development version of DBItest, the specs pass in the default context and in both contexts with `arrow = TRUE`.
DBItest 1.8.3 gates no spec above 1.8.1, so nothing changes with the released version.

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

With `lazy_strings = TRUE`, only a fetch with a character column that stays a view splits its arrays by column when they are one.
The arrays of such columns count towards the collections of the young generation that the section on chunking describes, in every fetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
An empty `utf8` array may come without an offsets buffer, as `nanoarrow_array_init()` builds it.
`arrow_concat_strings()` read the first and last offset of every array to sum the bytes of its strings, which for such an array reads through a null pointer.
It now counts no bytes for an empty array.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Measured on top of #802, converting every fetch of several arrays column by column took as long as the conversion of the layers below and peaked higher: 11 MB more for all five columns of five million rows and 89 MB more for the two text columns.
`nanoarrow::convert_array_stream()` keeps each array until the next garbage collection, where the layers below release it as soon as it is copied.
A fetch without a lazy column now takes the path of the layers below unchanged.
Only a fetch with a column that stays a view splits its arrays by column, in `arrow_lazy_to_df()`, so that the view holds the strings of its own column alone.
The data frames section of `?sqlite-arrow` describes the eager path as before and the split for lazy strings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The benchmark ran again on #802's head, on the merge that converted every fetch of several arrays column by column, and on the commit that keeps that conversion for lazy strings only.
The harness now reads the peak RSS before `object.size()`, which allocates a hash table for the strings of a column and materializes a lazy one: it added up to 170 MB to the peaks of the cells with text.
The README replaces the claim that the column-by-column conversion made the eager path faster and leaner, which no longer holds on the reworked layers, and updates the numbers for `lazy_strings`.
A full fetch of five million rows takes 3.6 s with lazy strings, 9.4 s eager and 16.4 s on the default path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

#802 now carries the final layers below it: a data frame fetch hands R a list of struct arrays with their formats, the columns of times in seconds, and the coercion warning, which `arrow_fetch_df()` raises after the conversion.
`arrow_to_df()` takes `lazy_strings` from the connection as a fourth argument and marks the text columns without a prototype or with a plain `character()` one; factors without levels stay out, since they are built from copies.
A fetch with such a column and at least one array converts its columns in `arrow_lazy_columns()`, which replaces only the conversion step: factors, times in seconds, the prototypes' attributes, the narrowing of integers and `bigint` follow as for the other fetches.
`arrow_split_columns()` now splits the list of arrays instead of a stream.
Eager fetches and fetches of no rows take the path of the layers below unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
With `extended_types = TRUE`, a lazy fetch gives the same data frame as an eager one, from one array or from one per row, with times outside a day in seconds and one coercion warning.
The views of the prototype test own their arrays and keep their values after a garbage collection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A fetch with a lazy column hands nanoarrow the arrays of its other columns, which keeps them until the garbage collector runs, and the collector does not see their memory.
Only the arrays of the lazy columns counted towards the collection of the young generation after every 64 MB, so a loop of chunked fetches piled up the others: 236 MB above the floor for all five columns of five million rows in chunks of 10,000 rows.
`arrow_split_columns()` now returns the bytes of each column, and `arrow_lazy_columns()` counts those of the other columns too, which brings that loop to 158 MB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The run on `fbd54c9` replaces the one on `de9734e`: the eager cells are those of the final layers below, and the lazy chunked loop counts all its arrays towards the collection trigger.
A full fetch of five million rows takes 3.6 s with lazy strings, 9.4 s eager and 15.7 s on the default path, and the lazy chunked loop peaks at 159 MB above the floor, against 133 MB eager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
This reverts commit 18269a8.

The declaration of the DBItest version moves to a layer of its own above this pull request, which stays about `lazy_strings`.
The DBItest contexts declare 1.8.1 again, as in the layers below.

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

krlmlr commented Nov 10, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by this comment.

One clean review of this pull request, at fe6e409, is addressed up to 4bb6a97: its High finding (lazy columns beyond 2 GiB) is fixed in c2b41f7 and 7fdae79, its Medium finding (Arrow DBItest runs without the driver and transaction groups) in b3600f4, and its Low findings are resolved; the declaration of DBItest 1.8.3.6 that it suggested left this pull request again in 4bb6a97. The integration review of the whole stack at 071560ec found only that the description describes code that is gone (finding 7). The description is rewritten. This list will be posted again once the fixes in the layers below are merged up. These remain:

  • R/arrow.R#L230: most vectorized uses of a lazy column convert its strings to R strings again, one by one and on every call: on two million strings, nchar(), == and substr() took about 0.7 s each on a lazy column against under 0.1 s on a copied one, while the lazy fetch saved about 2.4 s, so a column used more than a few times is better copied with c() first. Relevance: low; reviewer's confidence: high. (recorded)
  • R/arrow.R#L226: with lazy strings, a fetch leaves its arrays to the garbage collector, the array of a view with its column and those of the other columns at the next collection, so a loop over chunks of 10,000 rows that discards its data frames peaked at 159 against 133 MB above the floor eager, on five million rows, while it took half the time. Relevance: low; reviewer's confidence: high. (recorded)
  • tests/testthat/test-arrow-lazy.R#L135: the test of a lazy text column of 2100 MiB, which needs large_utf8, needs about 3.5 GB and runs only with RSQLITE_TEST_LARGE_ARROW=true. This repository's GitHub Actions checks set it since 1449720 of feat: Implement the DBI Arrow interface natively #795, which the current round merges up the stack, so it will run there but not on CRAN or users' machines; it passed locally, as did the review's case of 3072 rows of 1 MiB. Relevance: low; reviewer's confidence: high. (recorded)

Generated by Claude Code

…tesla-mja103-lazy

Brings in `dbColumnInfo()` answered from the Arrow columns, `POSIXlt` written like `POSIXct`,
the CI hook for the large Arrow test, and the comparison helper that can ask `dbColumnInfo()` before each fetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

Brings in the busy mark reset through `R_ExecWithCleanup()`, the checks of Arrow parameters,
the 64-bit row counter, the UTF-16 text in binary columns,
and `dbColumnInfo()` for the types requested with `schema` and `ptype`.
`src/cpp11.cpp` is regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

Brings in the bytes of a blob in a `utf8` column kept as they are, also in a UTF-16 database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

Brings in the state of the Arrow test hooks kept in each result,
with the helpers `set_bytes_limits()` and `fetch_with_bytes_limits()` in `helper-arrow.R`.
`src/cpp11.cpp` is regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
With `RSQLITE_TEST_LARGE_ARROW=true`, the process running the tests peaked at 5.3 GB.
The test of a value beyond SQLite's length limit left its 2 GiB buffer behind: nanoarrow frees an array built from R vectors one level of references per garbage collection, and six collections passed before it went.
The blob test of #314 that follows it in `test-blob.R` then added its own 2.8 GB.
`gc_until_stable()` in the new `helper-memory.R` collects until a collection frees nothing more, and that test now calls it once its arrays are gone.
The test of a lazy text column beyond 2 GiB calls it before and after it allocates, fetches 2049 strings of 1 MiB instead of 2100, and ends its chunks at 64 MiB instead of 1 GiB, so that copying them into one array needs little more than the column.
Its peak drops from 3.3 to 2.4 GB, and the whole suite peaks at 3.4 GB, in the blob test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

Brings in Arrow streams read safely on worker threads, with the "Threads" section of `?"sqlite-arrow"`,
the coercion warning reported as the stream's error off R's main thread,
the scanner tests, and the longjmp tests.
`helper-memory.R` and the cleanup at the end of the bind test of the Arrow interface
are the same on both sides and merge as one.
The lazy strings add no R call to the stream callbacks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…tesla-mja103-lazy

Brings in the atomic busy mark that records the thread holding a result, the atomic row count and completion,
the parked results closed from the main-thread entry points, NaN tested without R,
and the tests that read streams on a thread of their own.
`src/cpp11.cpp` is regenerated.

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

krlmlr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

One clean review of this pull request, at fe6e409, is addressed: its High finding (lazy columns beyond 2 GiB) in c2b41f7 and 7fdae79, its Medium finding (Arrow DBItest runs without the driver and transaction groups) in b3600f4, its Low findings resolved; the declaration of DBItest 1.8.3.6 it suggested is #831. The integration reviews of the stack (first integration review, second integration review) found nothing in this layer's code beyond the description, which is rewritten; the large lazy test peaks at about 2.4 GB since 63f16ca. Up to a24d0be, which closes the review rounds for the stack, these remain:

  • R/arrow.R#L230: most vectorized uses of a lazy column convert its strings to R strings again, one by one and on every call: on two million strings, nchar(), == and substr() took about 0.7 s each on a lazy column against under 0.1 s on a copied one, while the lazy fetch saved about 2.4 s, so a column used more than a few times is better copied with c() first. Relevance: low; reviewer's confidence: high. (recorded)
  • R/arrow.R#L226: with lazy strings, a fetch leaves its arrays to the garbage collector, the array of a view with its column and those of the other columns at the next collection, so a loop over chunks of 10,000 rows that discards its data frames peaked at 159 against 133 MB above the floor eager, on five million rows, while it took half the time. Relevance: low; reviewer's confidence: high. (recorded)
  • tests/testthat/test-arrow-lazy.R#L133: the test of a lazy text column of 2049 MiB, which needs large_utf8, peaks at about 2.4 GB with chunks cut at 64 MiB and runs only with RSQLITE_TEST_LARGE_ARROW=true, which this repository's GitHub Actions checks set through feat: Implement the DBI Arrow interface natively #795's hook, so it runs there but not on CRAN or users' machines; it passed locally, as did the review's case of 3072 rows of 1 MiB. Relevance: low; reviewer's confidence: high. (recorded)

Generated by Claude Code

…tesla-mja103-lazy

Brings in the Arrow test fixtures moved into `helper-arrow.R`,
with the wrappers of the tests of `schema` renamed to `validated_dbGetQueryArrow()`, `validated_dbReadTableArrow()` and `validated_dbFetchArrowChunk()`.

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

`is_lazy()` and `local_concat_utf8_max_bytes()` move from the top of `test-arrow-lazy.R` into `helper-arrow.R`, which `pkgload::load_all()` sources.
`is_lazy()` becomes `is_lazy_strings()`, since every test file sees the helpers and the Arrow tests also speak of lazy streams.
Every `test_that()` block now runs on its own after `load_all()`.

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

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Marked as a draft, as decided: this pull request is the reference for the reworked Arrow stack, which carries its changes in smaller, separately reviewed pull requests (see the plan). So far: #855, #856, #857, #859 to #867 (GitHub stack 851 on #830 and #850), and #852, #853, #854 and #858 from main. It will be closed once its replacements are merged.


Generated by Claude Code

krlmlr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Closed as superseded, as decided: the Arrow work is rebuilt from main as a chain of smaller pull requests, planned on #880. The data-frame path through Arrow that this stack carries (group D) is tracked in #881. The branch stays as a reference.


Generated by Claude Code

@krlmlr krlmlr closed this Nov 30, 2026
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