Skip to content

fix: Raise the warnings of dbFetch() after the fetch, and fix the read-side findings of the stack review - #977

Draft
krlmlr wants to merge 11 commits into
claude/rb-stack-review-writefrom
claude/rb-stack-review-read
Draft

krlmlr wants to merge 11 commits into
claude/rb-stack-review-writefrom
claude/rb-stack-review-read

Conversation

@krlmlr

@krlmlr krlmlr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What changes for users: dbFetch() raises its warnings about the values (mixed types, invalid UTF-8, dates, times and timestamps that can't be parsed) once the fetch has read its rows and the result is no longer busy. A warning made an error with options(warn = 2), or caught by tryCatch(warning = ), again loses only the rows of that fetch, which count in dbGetRowCount(), and the next fetch goes on after them, as in RSQLite 3.54.1. On the stack head such a warning ended the whole execution: dbHasCompleted() returned TRUE and every later fetch returned zero rows. A calling handler of these warnings can now fetch from the result or clear it. A date that can't be parsed no longer makes the next fetch convert its row again. The NEWS bullet of #935 is corrected accordingly.

The warnings are kept as runs of the same message with a count, so a column of many values that can't be converted costs about as much memory as on main; values whose messages alternate still take one entry per switch, so 3e6 alternating blob and unparsable text values peak at 460 MB against 204 MB on main (accepted). The warnings about the values read before an SQLite error are raised before that error, as on main. When an interrupt or an R error ends a data-frame fetch, its collected warnings are dropped along with its rows (accepted).

Arrow side (internal): an SQLite error during an Arrow fetch no longer counts the rows that the fetch read and lost, in line with the rule that rows count once they are returned (an interrupt already counted right). An interrupt of dbBind() on a result claimed for Arrow fetches is an interrupt again instead of an R error saying it "ended the Arrow fetches": the classifying interrupt check now runs only inside an Arrow fetch. The interrupt intervals are stated once (interrupt_interval(): 1024 rows or steps, 16384 in an Arrow fetch), and the comments that disagreed are fixed. Arrow arrays with NULLs zero the unused tail bits of their validity bitmap, so that valgrind no longer reports uninitialized bytes in IPC output. The comment on refused stream calls now says that only calls of the same stream are refused. Test-only paths are marked as such.

How it's tested: the data frame tests in test-fetch-error.R, test-fetch-error-rows.R, test-extendedTypes.R and a new test in test-dbClearResult.R fail on the base (red: 16 + 1 + 1 + 1 failures) and pass with the fix, covering warn = 2, tryCatch(warning = ), a kept SQLite error after the warning, the read lock, and a handler that fetches and clears. The busy-guard tests now trigger their in-fetch warning with the warning about dropped rows, which is still raised inside the fetch. The Arrow count tests in test-arrow-chunks.R ("lost, and not counted") fail on the base (3 failures) and pass with the fix. A new callr test interrupts a bind of an Arrow-claimed result (red on the base). Full suite with NOT_CRAN=true: FAIL 0, PASS 13485. Valgrind on all test-arrow-*.R files: 0 errors (two pre-existing valgrind-only failures in test-arrow-text.R from long double emulation); the reviewer's probe p4.R: 0 errors, 12 on the base.

Where it sits: a follow-up layer of stack #928 that fixes the read-side findings of the review of the whole stack, based on #976 (write-side fixes), on top of #971.

Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4



Generated by Claude Code

nanoarrow leaves the bits past the last row in the last byte of a validity bitmap uninitialized when the bitmap grows.
A consumer that copies that byte, such as the writer of an IPC stream, copied undefined values, which valgrind reported.

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

Only a call of the same stream is refused.
A fetch of the result by other means gets the rows after the chunk whose warnings run, before that chunk is handed out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…y the Arrow rows that are returned

The warnings about the values of a data frame fetch are collected and raised once the fetch has returned and the result is no longer busy, as for Arrow chunks.
A warning made an error with `options(warn = 2)`, or caught by `tryCatch(warning = )`, loses the rows of that fetch only, which count as fetched, and the next fetch goes on after them, as in RSQLite 3.54.1.
Before, it ended the execution.
A handler of these warnings can now fetch from the result or clear it.

An SQLite error during an Arrow fetch no longer counts the rows that the fetch read and lost.

The classifying interrupt check runs only inside an Arrow fetch:
an interrupt of `dbBind()` of a result claimed for Arrow fetches is an interrupt again, not an error that says it ended the Arrow fetches.
The fetches and binds check every 1024 rows or steps, Arrow fetches every 16384, as one function states.

Comments mark the code paths that only the tests use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
@krlmlr
krlmlr added this pull request to stack #928 December 1, 2026 11:55

krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Question: should a data frame fetch whose warning exits keep its rows for the next fetch, as an Arrow chunk does?

This pull request raises the conversion warnings of dbFetch() only after the fetch has finished, so that a handler that exits, or options(warn = 2), no longer ends the whole execution: as on main, the rows of that one fetch are lost and the next fetch continues with the rows after them. They are dropped at the warning loop in result_fetch(), where the unwind loses the data frame. Arrow fetches already keep such a chunk and hand it out on the next fetch (#962), so the two paths still differ in this corner.

  • Keep the main behavior for data frames: the rows of a fetch whose warning exits are lost, the execution continues, as implemented (recommended)
  • Keep the data frame for the next dbFetch(), as Arrow keeps its chunk: no rows lost and the two paths agree, but a fetch then returns rows that an earlier call already warned about, and the count and dbHasCompleted() need the same rules as for kept chunks

Kirill decides. Until then the first option stays as implemented.


Generated by Claude Code

claude and others added 5 commits December 1, 2026 12:08
…e its SQLite error

The warnings about the values of a data frame fetch are kept as runs of the same message with a count,
so that a column of many values that can't be converted no longer costs memory for each value.
They are raised as many times, in the same order, as before.

The warnings about the values of the rows read before an SQLite error are raised before the error, as in RSQLite 3.54.1,
once the fetch has left the busy guard.
The warnings about the columns are still left out for a failed fetch.

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

This branch has not been deployed

No deployments
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