Repository navigation
Conversation
… 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
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6
|
Review of this PR at fe6e409, by a Claude Code reviewer with clean context that read the diff against High1. Medium2. Restricting the Low3. Dead code after the column-stream rewrite. 4. "Freed as soon as converted" is one garbage collection later for the eager columns that From the review of r-dbi/DBItest#5715. Declare 6. Checked and found sound
Generated by Claude Code |
…tesla-mja103-lazy
krlmlr
left a comment
There was a problem hiding this comment.
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
…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
Superseded: Accepted limitationsSuperseded 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:
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
Accepted limitationsOne 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:
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
|
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 Generated by Claude Code |
|
Closed as superseded, as decided: the Arrow work is rebuilt from Generated by Claude Code |
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. DefaultFALSE.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, becausenanoarrow::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 ofarrow_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,bigintand the coercion warning, raised after the conversion, follow as for every other fetch.lazy_strings. A character column without a prototype, or with a plaincharacter()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 buildslarge_utf8when the strings need more than the 2^31 - 1 bytes thatutf8offsets 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 thatdbFetchArrowChunk()already triggers every 64 MB, since the collector does not see their memory. The option requiresarrow = TRUE, is validated and cloned likearrow, and is documented in?SQLiteand 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 withc()first.Tests.
tests/testthat/test-DBItest-arrow.Rand the newtest-DBItest-arrow-lazy.Rshare a helper,helper-DBItest-arrow.R, that builds the context and runs the groups that fetch or write data frames:test_driver(), which checksbigintwithdbGetQuery(), plustest_result(),test_sql(),test_meta(),test_transaction()andtest_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 keepsdbitest_version = "1.8.1"as the layers below do, and #831 declares the newer version.tests/testthat/test-arrow-lazy.Rcovers:large_utf8with a lowered limit;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 onfbd54c9, whose R and C++ code is that of this head. The harness now reads the peak RSS beforeobject.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.dbFetch(n = 10000)that discards its data frames: 3.3 s and 159 MB lazy, 6.8 s and 133 MB eager.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_versionis 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 withoutptypeand with two-row chunks, ran the tests under AddressSanitizer, and rangctorture()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 everytest_that()block runs on its own right afterload_all().is_lazy()is namedis_lazy_strings()there.https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Generated by Claude Code