Repository navigation
Conversation
`SqliteResultImpl::fetch_into()` reads the rows of a fetch into a `SqliteRowSink`, modeled on RPostgres's `PqRowSink`, and keeps everything the fetch did: the read-ahead when the sink is full, the kept error, the protected region that completes and resets the result, the rows of an SQLite error, and 64-bit row counts. `SqliteDataFrameSink` collects the rows of `dbFetch()` into a data frame. The interrupt check moves from `DbDataFrame::advance()` into the fetch loop. A sink can decline a row, which ends the fetch and leaves the row for the next one; the unexported `result_fetch_declining()` tests that seam. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Merge remote-tracking branch 'origin/claude/rb-result-ptr' into HEAD Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…w sink's contract `dbFetch()` checked that the result is bound in `fetch()` and again in `fetch_into()`. The fetch loop moves to the private `read_into()`, so that `fetch()` and `fetch_into()` each check once, before anything else, as before. The contract in `SqliteRowSink.h` now says when `finish()` runs: when the rows end, the sink has enough or declines a row, or an SQLite error ends the fetch, not when a call to the sink or an interrupt ends it, so a sink frees what it holds in its destructor. It also says that a sink with `remaining()` of -1 gets no read-ahead: the step must reach the next row for `takes_row()` to see it, so an SQLite error of that row ends the fetch, also if the sink would decline the row. New tests pin this with the declining test sink. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
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.
dbFetch()now reads its rows through a virtual row sink, as asked in #859 (comment), so that the Arrow layers later in this chain can fill a chunk with the same fetch loop instead of a second copy or a template.The new
src/SqliteRowSink.hdeclares the abstractSqliteRowSinkand documents its contract: the call order, what the sink owns and reads, and what may throw.SqliteResultImpl::fetch_into(SqliteRowSink&)checks that the result is bound and runs the fetch loop thatfetch_rows()had (in the privateread_into(), whichfetch_rows()calls after the check infetch(), so each path checks once), with everything it did: the read-ahead when the sink is full, the kept error, the protected region that completes and resets the result on any error (#935), the rows that an SQLite error carries (#945), the busy guard, and 64-bit row counts.SqliteDataFrameSinkwrapsSqliteDataFrame. The interrupt check moves fromDbDataFrame::advance()into the fetch loop, every 1024 rows of a fetch as before, so there is one place for it.The design follows
PqRowSinkfrom r-dbi/RPostgres#638 (begin(),append(),remaining()with -1 for unbounded, interrupts checked by the loop) and differs where SQLite or this chain needs it.takes_row()(default true) lets a sink decline a row: the fetch ends without an error and the statement stays on that row for the next fetch. A PGresult row is cleared afterappend(), but an SQLite statement keeps its row, and the Arrow byte limit needs this later; data frames don't use it.finish(failed)is called inside the protected region, so building the output (the data frame and its warnings) still completes the result if it fails, and it returns the partial rows that the SQLite error carries; RPostgres builds the data frame after the loop. It runs when the rows end, the sink has enough or declines a row, or an SQLite error ends the fetch, but not when a call to the sink or an interrupt ends it, so a sink frees what it holds in its destructor.append()takes no argument, because the sink's column sources read the statement they were made for, where RPostgres hands over each PGresult.remaining()returnsint64_t. Whenremaining()reaches 0 after an append, the loop steps past the row only to read ahead, as since #933. A sink withremaining()of -1 gets no read-ahead: the step must reach the next row fortakes_row()to see it, so an SQLite error of that row ends the fetch, also if the sink would have declined the row. Keeping that error would need the sink to know before the row that it is full, and such a sink can return 0 fromremaining()instead; the header says so. The warning aboutdbFetch()for statements stays in the data frame path, outside the protected region, so that it behaves as before; RPostgres moved it intofetch_into(). Running a writing statement sent withdbSendStatement()to the end (#948) stays instep()rather than in a discarding sink: it runs while binding, where no fetch and no sink exist.Tested by the existing suite (FAIL 0 | WARN 3 | SKIP 63 | PASS 11391 with
NOT_CRAN=true; the warnings are locale warnings of this machine). The newtests/testthat/test-row-sink.Rexercisestakes_row() == falsethrough a test-only sink behind the unexportedresult_fetch_declining(), which runs under the busy guard throughDbResult::fetch_into(): the declined row is returned by the nextdbFetch(), and the row count anddbHasCompleted()follow. Two more tests pin the error cases: an SQLite error in the row after the sink's last one ends that fetch and completes the result, and an error in a row after a declined one comes from the nextdbFetch().Layer R3 of the rebuilt chain, planned in #880; based on #949. Not ported from an old PR: it replaces the
fetch_loop()template of the old chain (#859).Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code