Repository navigation
Conversation
The internal `read_arrow_stream()` returns a `nanoarrow_array_stream` whose `get_next()` hands out the next Arrow chunk of at most `n` rows of the result, as `fetch_arrow_chunk_warn()` does: the same column types, warnings, kept chunks and errors. `get_schema()` reads the first chunk, which decides the types, and the result keeps it for the first `get_next()`. An error of a fetch reaches the consumer through `get_last_error()`. The stream reads the execution that is current when it is created, and fails with an error that says so once the result is bound to new parameters, using the count of executions of the result, or once the result is cleared: it refers to the result through a `std::weak_ptr`, so `DbResultPtr` is now a `std::shared_ptr`, as the vendored Boost has no `weak_ptr`. Creating the stream claims the result for Arrow fetches. A call from a handler of a warning that another call raised is refused, so that the chunks stay in order. No DBI method calls the stream yet: no change of behavior for users. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…o claude/rb-arrow-stream Takes the chunk from the result before R allocates, also in the stream. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
This was referenced Dec 1, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No change of behavior for users: the new stream is internal. DBI's default
dbSendQueryArrow()anddbFetchArrow()fetch data frames withdbFetch()and convert them with nanoarrow, so they don't reach this stream; the native methods that will use it come later in the plan (item 16).The internal
read_arrow_stream(res, n)returns ananoarrow_array_streamover the current execution of a result. Itsget_next()hands out the next Arrow chunk of at mostnrows, built by the chunk fetch of #954–#963 (fetch_arrow_chunk()on the result): same column types, byte limits and errors.get_schema()reads the first chunk, which decides the types, and the result keeps it (as a kept chunk of #962) for the firstget_next(), so no row counts as fetched before it is handed out. An empty result has a schema and no chunk.The conversion warnings of #961 are raised from R when a chunk is handed out, also when nanoarrow pulls the chunks. As in
fetch_arrow_chunk_warn(), the chunk is taken from the result before R allocates, and a warning made an error, a handler that exits or a failed allocation hands it back for the nextget_next(), which returns it without warning again. A call to the stream from a handler of its own warning is refused, so that the chunks stay in order within the stream's calls; this ordering holds per call only: a handler that fetches from the same result, or a second stream on the same result, can take chunks in between, and no rows are lost. An SQLite error of a fetch comes throughget_last_error(); R conditions that leave a callback by a jump (an interrupt, a warning made an error, the fetch-kind error) continue their jump once the C++ objects of the callback are destroyed.The stream reads the execution that is current when it is created, using the existing
executions_count of the result: afterdbBind()the nextget_schema()orget_next()fails with "Can't read an Arrow stream after its result has been bound to new parameters." The stream refers to its result through astd::weak_ptrand doesn't keep it alive: afterdbClearResult()(or R's garbage collector) it fails with "... after its result has been cleared." For that,DbResultPtris now astd::shared_ptr, since the vendored Boost has noweak_ptr. A schema read before stays readable. Creating the stream checks that the result is bound and claims it for Arrow fetches, sodbFetch()fails withRSQLite_error_fetch_kindbefore the stream reads a row.Left to later layers: a
release()from a handler during a callback and failures that stay final (F6b; a release from a warning handler duringget_next()is still unsafe here). Also left to F6b: a callback can currently continue R's longjmp through the consumer's frames underwarn = 2, an exiting handler or an interrupt; nanoarrow's R glue tolerates this, but a C++ consumer would not, and a stream that outlives its result or the package (F7). The callbacks call R, so they must run on R's main thread.Tested in the new
test-arrow-stream.R: schema before the first chunk and agreeing with the chunks, all rows in order across chunks (also throughnanoarrow::convert_array_stream()), empty results and results read to the end, warnings while pulling (throughstream$get_next(), also withwarn = 2, and through nanoarrow without it; F6b adds thewarn = 2case through nanoarrow), a refused call from a warning handler, an SQLite error mid-stream (inside a chunk and from the read-ahead step), release before the end, rebind, clearing the result while the stream is alive, the fetch-kind claim, and thencheck. The new test file is clean under valgrind (0 errors, no leaks); the full suite passes withNOT_CRAN=true(FAIL 0).Layer F6a of the rebuilt chain, planned in #880; based on #963. Ported from the basic stream of #864 (commit 2be01a8), without its
clear()that freed the result's implementation and without its shared ownership of the result.Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code