Skip to content

fix: dbColumnInfo() and dbFetch(n = 0) decide column types without converting values - #951

Draft
krlmlr wants to merge 1 commit into
claude/rb-row-sinkfrom
claude/rb-peek-types
Draft

krlmlr wants to merge 1 commit into
claude/rb-row-sinkfrom
claude/rb-peek-types

Conversation

@krlmlr

@krlmlr krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member

dbColumnInfo() and dbFetch(n = 0) now decide the column types of the next row without converting its values, so they raise no warnings. The types they return are unchanged.

What users see: before, these peeks read the next row into a one-row data frame and threw it away. Reading converts values, so a peek warned about things that the fetch returning the row warns about again: dates, datetimes and times that extended_types = TRUE can't parse ("Unknown string format", "Cannot convert blob"), and values of mixed types after an earlier fetch had fixed the column types. A peek also failed with "out of memory" when SQLite couldn't convert a large text value. Reading a blob as text also turned it into text for the following fetch, which then didn't warn about a blob in a character column. Now the peeks raise none of these, and the fetch that returns the row warns exactly as it does without a peek. NEWS has a bullet under Bug fixes. Because dbColumnInfo() no longer raises warnings, I narrowed the #934 bullet to warnings that dbFetch() raises, and removed the test where a warning handler of dbColumnInfo() tried to clear the result: no such handler can run any more. A new test checks that dbColumnInfo() doesn't warn on that same data.

Question for the maintainer: is it OK for these warnings to disappear from the peek? They come back in the fetch that returns the row, so users still see each of them once.

How: DbColumnStorage::get_value_data_type() holds the rule that a fetch uses when it stores a non-NULL value: the storage class through get_data_type() (the declared type for dates with extended types, and sqlite3_column_int64() for an INTEGER, which converts nothing), with integers widening to integer64 or double. append_data() uses the same function. DbColumn::peek_type() applies it to the current row, and DbDataFrame::peek_data() builds zero-row columns of those types with DbColumnStorage::allocate(). A peek calls no fetch_*(). This lets the Arrow layers drop the storage-class re-reading, which was only needed because a peek could convert the row.

Tests: I compared the base and this branch on a matrix of 10 declared types (including no declared type and an expression) × 11 first-row values (NULL, int, int64, real, text, date/time/datetime text, blob, invalid UTF-8 blob and text) and an empty result × all four bigint values × extended_types × check_utf8, plus a second-row matrix after dbFetch(n = 1): 8240 cases in all. The dbColumnInfo() and dbFetch(n = 0) results are identical in every case. On the base, 1356 of the 4120 peeks warned, and in 46 cases a peek removed the mixed-type warning from the following fetch. On this branch no peek warns, and every following fetch matches the same fetch without a peek. test-column-types.R pins this matrix: the types of the peek match those of the fetched rows, there are no warnings, and the later fetch is unaffected. Explicit dbColumnInfo() types pin representative cases. Red → green: on the base, the matrix tests, the two focused tests (an unparsable DATE, and a blob after text in a TEXT column) and the rewritten out-of-memory test (dbFetch(n = 0) under a heap limit fails with "Cannot read column 2: out of memory") fail, and on this branch they pass. Full suite with NOT_CRAN=true: FAIL 0, WARN 3 (zh_TW locale unavailable), SKIP 63, PASS 11446.

Layer R4 of the rebuilt chain, planned in #880; based on #950. There is no old PR to port: this layer is new in the rebuilt chain.

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



Generated by Claude Code

…t converting values

The peek took the types of the next row by reading its values into a data frame of one row.
Reading converts a value, which raised warnings about values that the fetch returning the row warns about again,
such as dates that `extended_types = TRUE` can't parse or values of mixed types,
and could fail when SQLite ran out of memory for a large text value.
Reading a blob as text also turned it into text for that fetch,
which then didn't warn about a blob in a character column.

The peek now decides each column's type from the declared type and the storage class,
with the rules that a fetch uses when it stores a value,
and builds zero-row columns of those types.
The types are the same as before for every combination of declared type, storage class, `bigint` and `extended_types` tested.

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 03:52

krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Question: may dbColumnInfo() and dbFetch(n = 0) stop raising conversion warnings?

This pull request makes dbColumnInfo() and dbFetch(n = 0) decide the type of each column from the current row without converting its values, so that the Arrow layers no longer need to re-read storage classes after a peek. The types they return are unchanged: in 8240 combinations of declared types, storage classes of the first two rows, bigint, extended_types, check_utf8 and empty results, both functions return exactly what they return on the base. What changes is what users see besides the types. On the base, a third of these peeks warned (a mixed type, "Unknown string format" for an unparsable date, "Cannot convert blob"), dbFetch(n = 0) failed with "out of memory" on a large UTF-16 text value, and in 46 cases the peek turned a blob into text and so hid the mixed-type warning of the next fetch. With this pull request, no peek warns, and each warning comes once, from the fetch that returns the row; every fetch after a peek returns and warns exactly as the same fetch without the peek. NEWS.md has a bullet under Bug fixes.

  • Accept it: a peek warns about nothing, and the fetch that returns a row warns about it (recommended: the warnings are about values the peek doesn't return, they came twice before, and a peek no longer changes what the next fetch sees)
  • Keep the warnings in the peek, by converting the first row as before only to warn, which keeps the base's double warnings and the hidden ones

If nobody decides, the recommended option stands.


Generated by Claude Code

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