Skip to content

feat: Request Arrow types for result columns with schema - #801

Closed
krlmlr wants to merge 44 commits into
claude/elegant-tesla-mja103-warningsfrom
claude/elegant-tesla-mja103-schema
Closed

krlmlr wants to merge 44 commits into
claude/elegant-tesla-mja103-warningsfrom
claude/elegant-tesla-mja103-schema

Conversation

@krlmlr

@krlmlr krlmlr commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Stacked on #800 (base branch claude/elegant-tesla-mja103-warnings), which is stacked on #796 and #795.

dbSendQueryArrow(), dbGetQueryArrow() and dbReadTableArrow() gain a schema argument that fixes the Arrow types of some or all result columns before the first row is read:

dbGetQueryArrow(con, "SELECT * FROM t", schema = list(id = na_int32(), when = na_timestamp("ms", "UTC")))
  • schema is a struct nanoarrow_schema, an arrow Schema, or a named list of column types. Entries are matched to the result columns by name, exactly: a name that is not in the result, a name the result carries twice, an unnamed entry, and a data frame (use nanoarrow::infer_nanoarrow_schema(), or the upcoming ptype) are errors. The form of schema is evaluated and checked before the query is sent, the names and types once it has been sent, so a statement with side effects has run when they fail; no result is left open either way.
  • A column with a requested type is typed without looking at its values: no widening, no dependence on chunk_size or on NULL first rows, and its declared type and extended_types play no part. The other columns are typed as before. The request outlives dbBind(), so a query executed several times keeps its types. When every column has a requested type, get_schema() no longer reads the first chunk, so the warning for the first chunk comes with its array.
  • With dbConnect(arrow = TRUE), dbFetch() of a result sent with schema keeps the requested types: they take precedence over the seconds in which a data frame fetch holds decided times and timestamps, so a requested time or timestamp has its unit, time zone and time of day, and over the types carried over to a new binding after dbBind(). Every requested format is converted to R by nanoarrow's prototypes, uint64 like int64.
  • The column builder now fills every scalar type of Arrow that SQLite values can be read into: null, bool, int8 to int64, uint8 to uint64, float, double, utf8, large_utf8, binary, large_binary, date32, date64, time32 and time64 in any unit, timestamp in any unit and time zone (read as UTC, labelled with the zone). Dictionary, decimal, nested and extension types are rejected with the column name. The large types never end a chunk at feat: Implement the DBI Arrow interface natively #795's byte limits, since their 64-bit offsets cannot overflow; the rows kept for a schema are split correctly for every requested type. A number in a date column is a count of days, truncated; in a time or timestamp column it is a count of seconds. Times and timestamps are rounded to the nearest tick of their unit, a time to the last tick of the day at most: exactly for integers and for text, which is read to the microsecond, and in double precision for reals. Every array the tests build passes arrow's ValidateFull() where arrow is installed.
  • Values of another storage class follow one set of rules, for requested and decided types alike, documented in ?"sqlite-arrow": integers into floating point and text types, reals into text types and text into binary types are silent; text and blobs into numeric types, reals into integer types (truncated) and into bool (true unless zero) are converted with the warning from feat: Report coerced values once per chunk or dbFetch(), with their rows #800; text or a blob that is not valid UTF-8 without NUL bytes becomes NULL in a stream (in a data frame, text ends at its first NUL, as on the default path), and a number outside the range of an integer type (including a real or text beyond 64 bits, which SQLite would saturate), a finite number beyond float, a date outside its type, a time outside a day (0 up to 24 hours excluded), a timestamp outside the range of its unit, an unparsable date or time, and any value in a null column become NULL with the warning (invalid_utf8, out_of_range, null_type). uint64 reads reals and text up to 2^64 − 1. Three tests of the layers below relied on these warnings and were updated: two of feat: Report coerced values once per chunk or dbFetch(), with their rows #800 on an integer-into-text warning, and the comparison of the data frame path with the default path, which now puts a number rather than text into a blob column. Unlike the default path, data frame fetches through Arrow don't warn for these exact conversions, as ?"sqlite-arrow" now says.
  • dbGetQueryArrow() and dbReadTableArrow() get explicit methods, since DBI's defaults would pass schema on to dbFetchArrow() or drop it; dbReadTableArrow() takes any name that dbQuoteIdentifier() takes, such as a string, SQL() or Id().
  • dbColumnInfo() is not touched; a new internal result_column_names() reads the names from the prepared statement without stepping it.

The ptype counterpart for data frames fetched with dbConnect(arrow = TRUE) follows in the next PR of the stack.

Review

Two clean-context reviews: the first (2026-09-27) found one Low issue and two nits; the second confirmed those fixes and three bugs found on the way, and found three Medium issues (reals and text beyond 64 bits saturating in int64/uint64, numbers beyond 32 bits wrapping into wrong dates, time32/time64 arrays that Arrow rejects for values outside a day) and four Low ones. All are fixed. #800 is merged up to dc4776e; the remaining limitations will be listed in an "Accepted limitations" comment after a final clean review of the whole stack.

Since the integration review: a requested uint64 makes a data frame column a double once a value is beyond 2^63 - 1, instead of wrapping it to a negative number (bed2527; the stream keeps the exact value); dbColumnInfo() names, for every format a schema can request, the R type that dbFetch() returns (9789588, 221b2f3); and a number of days beyond 32 bits in a DATE column, NA with a warning here and a wrapped date on the default path, is listed among the documented differences (4293d3f, 91b31f7).

What remains is listed under Accepted limitations.

The test fixtures this pull request adds live in tests/testthat/helper-arrow.R, so every test_that() block runs on its own right after load_all(). The wrappers that validate every Arrow result in test-arrow-schema.R are named validated_dbGetQueryArrow(), validated_dbReadTableArrow() and validated_dbFetchArrowChunk(), so that they do not mask DBI's functions in other test files.

https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6


Generated by Claude Code

`dbSendQueryArrow()`, `dbGetQueryArrow()` and `dbReadTableArrow()` take a
`schema` that fixes the Arrow types of some or all result columns before
the first row is read:
a struct nanoarrow schema, an arrow Schema, or a named list of column types,
matched to the result columns by name, exactly.
A requested type is used without looking at the values,
so it does not depend on the chunk size or on NULL rows,
and it is kept when the query is executed again with `dbBind()`.

The column builder fills every integer, floating point, text, binary,
date, time and timestamp type of Arrow, with a range check for the
narrow integer types.
Values of another storage class follow one set of rules for requested and
decided types alike:
integers into floating point and text types and text into binary types
are silent, text and blobs into numeric types and reals into integer types
are converted with the warning, and a blob that is not valid UTF-8,
a number out of range and an unparsable date or time become NULL.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6

krlmlr commented Sep 27, 2026

Copy link
Copy Markdown
Member Author

Review of this PR at 4b49166, by a Claude Code reviewer with clean context that read the diff against claude/elegant-tesla-mja103-warnings, ran targeted R snippets against a build of the whole stack, and posted nothing itself. Line numbers refer to that commit. "Confirmed" means reproduced by running code.

Low

1. dbReadTableArrow(con, Id(...), schema = ...) silently ignores schema. The method in R/dbReadTableArrow_SQLiteConnection_character.R is registered for c("SQLiteConnection", "character") only, so Id and SQL names hit DBI's default, which drops .... Confirmed: the format stays l with na_int32() requested. dbReadTable(con, Id(...), ptype = ) on #802 works because DBI delegates Id to the character method there. Suggested fix: register the method for Id and SQL as well, or for "ANY" through dbReadTable_toSqlName().

2. Nit. In arrow_set_schema() (R/arrow.R:172) the first term of ambiguous, tabulate(positions, length(columns))[positions] > 0, is always TRUE, so only the vapply() term does the work.

Checked and found sound

  • set_arrow_schema() is accepted only before the first Arrow fetch, survives dbBind(), and rejects dictionary, decimal, nested and extension types at send time with the column name.
  • The integer range checks exclude INT_MIN from int32 through INT64_C, promote_to_double() runs only while a column is unfrozen, and get_schema() skips the pending chunk when every column has a requested type.
  • The coercion policy applies alike to requested and decided types, as documented; test-arrow-schema.R passes on the build of the whole stack.

Generated by Claude Code

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The findings of the clean-context review, placed on the code they concern; the summary comment above carries the full report and the checks that came out sound.


Generated by Claude Code

Comment thread R/arrow.R Resolved
Comment thread src/SqliteArrowColumn.cpp Resolved
…nt-tesla-mja103-schema

Brings in the reworked layers below, at 4a4e580.
The column builder keeps the kinds, the unit and the time zone of this branch on top of the state of #800:
the storage class read once per row by `read_row()`, the bytes read once by `fetch_bytes()`, the open typing of data frame fetches, `wide_ints`, and the `null_type` reason.
`append_integer()`, `append_string()` and `append_binary()` read the current row's value like #800 does, and `fetch_bytes()` also serves `large_utf8` and `large_binary`.
`set_type()` and `init_array()` become const members, since the time types take the column's unit and time zone.
A requested type freezes its column from the start, so `reopen()`, `peek_value()` and `conform_chunk()` leave it alone.
`DbResult::set_arrow_schema()` keeps its `is_active()` check, which #800 dropped from the reads of a stream.
The generated dependency files are those of #800, regenerated through `src/Makevars.deps`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…e converts exactly

This branch converts integers and reals into a text column and text into a blob column without a warning, the default path warns for them.
Since #800, `?"sqlite-arrow"` says that both paths warn on the same fetches apart from truncated reals, and a test compares them on a blob column that receives text.
The documentation now names these silent conversions as a second exception, and that test puts a number into the blob column, which both paths report.
A new test pins the difference for text and blob columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The method was registered for character names only, so an `Id()` reached DBI's default method, which drops `schema` with the rest of `...`.
It is now registered for any name, quotes it with `dbQuoteIdentifier()` and rejects a name that does not quote to a single identifier, like DBI's default.

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

The first term of the old condition was always true for a matched name, so only the count of each name in the result decided.
A requested name is now ambiguous if it is among the duplicated result names, with the same error.
The tests add several ambiguous names, and a duplicated result name that is not requested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
When a column without a requested type makes the schema fetch the first chunk, a later fetch with a smaller `chunk_size` copies its rows.
The copy knew only the storage types of the decided types and failed with an internal error for `bool`, the narrow and unsigned integers, `float`, `large_utf8` and `large_binary`.
It now copies the storage types of every type that can be requested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A requested `time32` failed the whole stream with "Can't append to Arrow array" for a value beyond 2^31 units, such as a number of seconds.
A timestamp in nanoseconds outside the years 1677 to 2262 overflowed the cast to a 64-bit integer, which is undefined and wrapped in practice.
Both are now `NULL` with the coercion warning and the `out_of_range` reason, like an integer outside the range of a narrow type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The review found that a value in a column of the null type was reported as converted, although it becomes `NULL`.
Since #800 such values have the reason `null_type`, worded as "dropped by the null type, NA", and this holds for a null type requested with `schema` too.

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

When every column has a requested type, the schema of a stream reads no rows, so the warning for the first chunk comes with its array.
`?"sqlite-arrow"` said that the schema always fetches the first chunk, in the sections on result columns and on chunking.
It also said that each data frame fetch through Arrow decides the types of its columns, while a column with a requested type keeps it, and nanoarrow converts it.
The list of values that become `NULL` now includes those of a column of the null type.
New tests pin the schema that reads no rows, and data frame fetches of one or several chunks that keep a requested null type and `int64`.

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

The byte limits of #795 keep the 32-bit offsets of `utf8` and `binary` from overflowing.
The 64-bit offsets of the large types need no cut, so a requested `large_utf8` or `large_binary` column reads its bytes once per value but reports none for the limits.
The test runs the limits test of #795 with each requested string and binary type.

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

Since #800 the warning names a column's type when it is raised, from the kind of the column builder.
Each value of another storage class into each requested type now checks that name.

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

A data frame fetch through Arrow keeps a column as `integer64` once one of its integers has needed 64 bits, like the default path.
The append of a value notes this for `int64` and a requested `uint64`, the look at the next row of a fetch of no rows noted it for `int64` only.

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

krlmlr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review of the fixes at 30592db (the merge of #800 in 9fa916c and the ten commits after it), by a Claude Code reviewer with clean context that read the PR description, the first review, the merge's combined diff and the ten commits, built the commit with pkgload::load_all(), ran tests/testthat/test-arrow*.R and both DBItest files (0 failures with NOT_CRAN=true; the opt-in large test was not run), filled every requestable type from a 43-value matrix of storage classes and boundary values with arrow's ValidateFull(), and reverted five fixes locally to see their tests fail, and posted nothing itself. Line numbers refer to that commit. "Confirmed" means reproduced by running code.

The first review's findings

  • dbReadTableArrow(con, Id(...), schema = ) ignored schema: fixed: the method is now registered for "SQLiteConnection" alone and quotes any name through dbQuoteIdentifier() (R/dbReadTableArrow_SQLiteConnection.R:3-13); confirmed for a plain name, a name with a space, SQL(), a quoted identifier, Id(table), Id(schema, table) and a temp table, and the test fails when the old character method is restored.
  • Nit, the always-true tabulate() term in arrow_set_schema(): fixed: R/arrow.R:205 is now requested[requested %in% columns[duplicated(columns)]], with a test for several ambiguous names.
  • Nit, a value dropped by a null column logged as converted: fixed: it is logged as null_type (src/SqliteArrowColumn.cpp:602) and reads "dropped by the null type, NA" (R/warn-coercion.R:59); confirmed for a requested null type on the stream and data frame paths.

New findings

Medium

1. A real or text value beyond 64 bits saturates in a requested int64 or uint64 column and is reported as converted, so UINT64_MAX cannot be read into uint64. Confirmed: with schema = list(x = na_uint64()), SELECT 18446744073709551615 and SELECT 1e19 (both fit uint64, SQLite stores them as REAL) come back as 9223372036854775807 with "2 real values converted"; with na_int64(), 9223372036854775808, 1e30, 9e999 and '99999999999999999999' come back as INT64_MAX, and -1e30 as INT64_MIN, all as converted. The same values in int8 to uint32 are NULL with out_of_range, which is what R/arrow.R:91 documents for "a number outside the range of an integer type". The cause is that in_range() only sees the result of sqlite3_column_int64(), which clamps (src/SqliteArrowColumn.cpp:619-624, :670-673). Suggested fix: for a REAL value read sqlite3_column_double() first and log CR_OUT_OF_RANGE outside [-2^63, 2^63) (or [0, 2^64) for uint64, appending through ArrowArrayAppendUInt()), and treat text that parses beyond the range the same way; add UINT64_MAX, 2^63 and 1e30 to the range test.

2. A number beyond 32 bits in a requested date32 or date64 column wraps silently into a wrong date, with no warning. Confirmed: with na_date32(), SELECT 4294967296 + 18000 gives 2019-04-14, 2^53 + 1 gives 1970-01-02, 1e30 gives 1969-12-31; with na_date64(), 2147483648 gives -185542587187200000 ms and 1e10 gives 121829651251200000 ms. Milliseconds since the epoch stored as integers and requested as date64 are a plausible way to hit this. append_date() (src/SqliteArrowColumn.cpp:710-726) takes the days from parse_date(), which reads numbers through the 32-bit sqlite3_column_int() (src/SqliteColumnDataSource.cpp:139), a parser shared with the default path, and has no range check of its own; the rules in R/arrow.R:89-94 name no outcome for dates. Suggested fix: in append_date() read a numeric value with sqlite3_column_double() (or _int64()), and make it NULL with CR_OUT_OF_RANGE outside the int32 days of date32, or outside the days whose milliseconds fit 64 bits for date64; document it next to the time rule.

3. The requested time32 and time64 types hand out arrays that Arrow rejects when a value is not a time of day. Confirmed with arrow::Table$ValidateFull() for all four unit combinations: "time32[s] -1 is not within the acceptable range of [0, 86400) s". Sources are negative numbers, numbers of 86400 seconds or more, text such as '24:00:00' or '2020-02-03' (parsed as 2020 hours), and rounding: '23:59:59.6' in time32[s] becomes 86400. The range check added in 5cef549 compares against the storage integer only (src/SqliteArrowColumn.cpp:756-761), so R/arrow.R:92 ("a time ... outside the range of its unit") holds for the integer but not for the type. The decided time64[us] of extended_types = TRUE from the layers below has the same gap (a TIME column holding 100000 fails ValidateFull() without any schema). Suggested fix: for AK_TIME32 and AK_TIME64 use the limits 0 <= value < 86400 * scale and log CR_OUT_OF_RANGE otherwise, clamping the rounding at the last tick of the day or truncating instead of rounding.

Low

4. An error in evaluating the schema argument itself leaves the result open. Confirmed: dbSendQueryArrow(con, "SELECT 1 AS a", schema = list(a = nanoarrow::na_time32("us"))) and dbGetQueryArrow(con, sql, schema = list(a = undefined_type)) fail, and the next query warns "Closing open result set, pending rows". schema is a promise that is first forced at !is.null(schema) (R/dbSendQueryArrow_SQLiteConnection.R:10), after dbSendQuery() on line 9 and outside the tryCatch(). Every error raised inside arrow_set_schema() does clear the result. Suggested fix: force(schema) before dbSendQuery(). Related, by design of sending first: a statement with side effects has already run when the validation fails (confirmed: INSERT ... RETURNING a with schema = list(b = ) errors and the row is inserted); a sentence in the docs would do.

5. Times and timestamps are scaled in double precision, so the edges of the nanosecond unit and exact large integers are off. Confirmed: '2020-02-03 04:05:06.000001' in timestamp[ns] is 1580702706000001024, not ...1000; '2262-04-11 23:47:16.854775' fits int64 nanoseconds but becomes NULL with out_of_range, while '1677-09-21 00:12:43.145224', which does not fit, becomes INT64_MIN without a warning; the integer 9007199254740993 in timestamp[s] becomes 9007199254740992 silently, and INT64_MAX seconds becomes NULL although it fits. All follow from std::floor(seconds * scale + 0.5) on a double (src/SqliteArrowColumn.cpp:755-757). Suggested fix: take an INTEGER value through sqlite3_column_int64() with a checked multiplication, and for text scale the parser's whole microseconds in integers; otherwise document that the nanosecond unit is exact only to about 256 ns for current dates.

6. A requested float takes values outside its range as Inf without a warning, and bool reads a fraction as FALSE. Confirmed: 1e300 and -1e300 in na_float() are Inf and -Inf with no warning (the cast of an out-of-range double to float inside nanoarrow is also formally undefined), and 16777217 becomes 16777216 silently, which the "integers into a floating point type" rule covers; in na_bool(), 0.5, -0.9 and 'true' are FALSE with converted, because the value is truncated to an integer before value != 0 (src/SqliteArrowColumn.cpp:566-575, :619, :632-636). Suggested fix: log CR_OUT_OF_RANGE and append NULL for a finite double beyond FLT_MAX in an AK_FLOAT column; for bool, test a REAL value with != 0.0, or say in the docs that it is truncated first.

7. On the data frame path, a requested int64 column forgets that it needed 64 bits when the wide value was a real or text. Confirmed with arrow = TRUE and schema = list(x = na_int64()) over 5e9, 1, 2: dbFetch(rs, 1)$x is integer64, the next dbFetch(rs, 1)$x is integer; with the integer 5000000000 both are integer64. note_integer() only runs for values of storage class INTEGER (src/SqliteArrowColumn.cpp:625-629, and :172 in peek_value()). Suggested fix: call note_integer(value) for every value appended to an AK_INT64 or AK_UINT64 column.

Checked and found sound

  • The merge 9fa916c: the combined diff of the six conflicted files keeps both sides: set_arrow_schema() keeps its is_active() check while arrow_schema() drops it as on feat: Report coerced values once per chunk or dbFetch(), with their rows #800, fetch_bytes() covers the large types, set_type() and init_array() became members so chunks rebuilt by conform_chunk() carry the unit and time zone, and the all_frozen shortcut sits before feat: Report coerced values once per chunk or dbFetch(), with their rows #800's warn_coercions(). Generated docs are in sync.
  • Every requestable type (null, bool, int8 to uint64, float, double, utf8, large_utf8, binary, large_binary, date32, date64, time32[s|ms], time64[us|ns], timestamp in four units with and without zone) is filled from integers, reals, text, blobs and NULL; apart from findings 1 to 3, 5 and 6 the values and reasons match the documented rules, and all arrays except the time ones pass ValidateFull().
  • The chunk kept for the schema: with all 26 type variants requested next to one open column, first chunks of 14, 9 and 5 rows split by later chunk_size of 1, 3, 4 and 14 give the same table as an unsplit read for every requested column. Reverting 04c8c27 makes its test fail.
  • The data frame path does not re-decide requested columns, over fetches of 0, 1 and all rows, one or two rows per chunk, and after a stream fixed the types, while an open column still widens. Reverting 30592db makes its test fail.
  • Byte limits: requested utf8 and binary end chunks (also when split from the kept chunk and on the data frame path), large_utf8 and large_binary never do, and all four give valid arrays with the same values. Making the large types count again makes the test of 43fdcaa fail.
  • Requests survive dbBind() with new parameters, dbBindArrow(), and params = given to dbSendQueryArrow() and dbGetQueryArrow().
  • Validation errors raised inside arrow_set_schema() leave no result open, for every invalid entry and rejected type tried, on parameterised queries and through dbGetQueryArrow() and dbReadTableArrow(). Reverting 5cef549 and 9e5b3ac makes their tests fail too.

Generated by Claude Code

krlmlr pushed a commit that referenced this pull request Nov 10, 2026
…-tesla-mja103-ptype

Data frame fetches through Arrow now go through `result_fetch_arrow_df()`, which types each fetch like the default path and reports which columns needed 64-bit integers.
`arrow_fetch_df()` reads the prototype from the result and passes it to `arrow_to_df()`, which converts the stream with the prototype's types.
`arrow_df_int64()` takes both `wide_ints` and the columns to keep, so that a column with a prototype is neither narrowed to `integer` nor touched by `bigint`.
The documentation of `ptype` moves next to the new rules for typing data frame fetches.
The dependency files of #801 replace the ones with system headers that the auto-update had committed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…ed integer type

SQLite saturates a real or the integer at the start of a text at 64 bits, so `int64` took `1e30` as `2^63 - 1` and reported it as converted.
`uint64` saturated the same way, and could not hold any value above `2^63 - 1`.
A real is now truncated and checked against the range of the type before the cast, and a saturated text or blob is read again digit by digit.
Values beyond the range become `NULL` with the `out_of_range` reason, and `uint64` takes reals and text up to `2^64 - 1`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
… beyond its range

The parser shared with the default path reads a number in a date column with the 32-bit `sqlite3_column_int()`, so a requested `date32` or `date64` wrapped a number beyond 32 bits into a wrong date, without a warning.
The Arrow column now reads the number itself, as a 64-bit integer or a truncated real, and leaves the shared parser alone.
A count of days whose `date32` days or `date64` milliseconds don't fit the type becomes `NULL` with the `out_of_range` reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Arrow's `time32` and `time64` hold a time of day, from 0 up to 24 hours excluded, and `ValidateFull()` rejects other values.
The column checked only the range of the storage integer, so a negative number, 24 hours or more, text such as `'24:00:00'`, and `'23:59:59.6'` rounded to `time32[s]` gave arrays that Arrow rejects.
A time outside the day now becomes `NULL` with the `out_of_range` reason, and rounding stops at the last tick of the day.
The new test helper `arrow_validated()` checks arrays with `ValidateFull()` where arrow is installed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Times and timestamps were scaled to their unit in double precision.
A timestamp in nanoseconds was off by up to a few hundred nanoseconds for current dates, the edges of its range were wrong in both directions, and integers above `2^53` seconds lost their last digits.
An integer is now scaled with a checked 64-bit multiplication, and text is parsed to whole microseconds and scaled or rounded in integers, with the parsers of `extended_types`.
A real is still rounded in double precision, as documented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…d read a real into `bool` as a real

A finite double beyond the range of `float` became infinite without a warning, through a cast that C++ leaves undefined.
It now becomes `NULL` with the `out_of_range` reason, while an infinite real stays infinite.
A requested `bool` truncated a real to an integer first, so `0.5` became false; a real is now true unless it is zero, still reported as converted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A data frame fetch through Arrow keeps a column as `integer64` once one of its values has needed 64 bits, like the default path.
Only values stored as integers were noted, so a requested `int64` or `uint64` column fell back to `integer` in the next fetch when the wide value was a real or text.
Every value appended to such a column is now noted, also when a fetch of no rows looks at the next row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…ypes of data frame fetches

Since #800, a data frame fetch through Arrow holds decided times and timestamps as seconds, and starts a new binding from the types of the last one.
The merge lets a requested type take precedence over both.
A requested `time32` and `timestamp` give their unit, time zone and time of day in a data frame, and a requested `int32` holds for every binding where the default path would carry text over.

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

Since #800, a data frame fetch through Arrow converts its arrays by their formats, which the merge extends with nanoarrow's prototypes for the formats of requested types.
The test fetches every requestable type through `dbFetch()`, in one array and in arrays of two rows, and checks the R values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…ke text itself

Since #795, a stream also makes text that is not valid UTF-8 `NULL`, which the section on result columns says.
The list of rules for requested types named only blobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
`nanoarrow::as_nanoarrow_array()` of a stream needs arrow, which is only suggested and missing from CI's smoke job.
Five schema tests failed without it.
They now take the array through the new helper `single_array()`, which collects the stream with nanoarrow alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
krlmlr pushed a commit that referenced this pull request Nov 10, 2026
…-tesla-mja103-ptype

`arrow_to_df()` now converts the list that `result_fetch_arrow_df()` returns, with the formats, names and arrays of a fetch.
It takes the prototype as its third argument, puts its columns into the conversion target by position, and turns the factors without levels into factors after the conversion.
The columns of the prototype stay out of the narrowing of 64-bit integers and out of `bigint`, which `arrow_df_int64()` used to do and `arrow_to_df()` now does itself.
The coercion warning stays where #801 raises it, after the conversion in `arrow_fetch_df()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…ata frame path

With `extended_types = TRUE`, the default path reads a number in a `DATE` column as days in 32 bits and wraps a larger one into another date without a warning.
Since b99d110 the Arrow path reads the number in full and makes a number of days beyond 32 bits `NA`, reported as out of range.
`?"sqlite-arrow"` now lists this as the fourth difference of the data frame path and as an exception to the default path warning on the same fetches.
Numbers in `TIME` and `TIMESTAMP` columns are seconds as doubles on both paths and show no such gap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…mns with the default path

The comparison of unparsable times through Arrow gains a `DATE` column and a row with numbers beyond 32 bits.
Its days beyond 32 bits are wrapped silently on the default path and `NA` with one out-of-range warning per fetch through Arrow, over several fetch sequences.
The `TIME` and `TIMESTAMP` columns hold the same numbers and stay identical on both paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

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.
The documentation of the data frame path keeps the sentence on `dbColumnInfo()` and the four differences.

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

krlmlr commented Nov 10, 2026 •

Copy link
Copy Markdown
Member Author

Accepted limitations

Two clean reviews of this pull request, at 4b49166 and 30592db, and both integration reviews of the stack (first integration review, its finding 2 fixed in 4293d3f and 91b31f7; second integration review, its parser finding fixed here in c5d9c5f) are addressed up to 10b65d2, which closes the review rounds for the stack. Every High and Medium finding is fixed; since the first integration review, a requested uint64 beyond 2^63 - 1 becomes a double in data frames instead of wrapping (bed2527), and dbColumnInfo() names the R type dbFetch() returns for every requestable format (9789588, 221b2f3). These remain:

  • R/arrow.R#L74: the names and types of schema are checked once the query has been sent, only its form before, so a statement with side effects, such as INSERT ... RETURNING, has run when they fail; no result is left open. Relevance: low; reviewer's confidence: high. (recorded)
  • R/arrow.R#L183: data frame fetches through Arrow convert integers and reals into a text column and text into a blob column silently, where the default path warns. Relevance: low; reviewer's confidence: high. (recorded)
  • R/arrow.R#L94: a requested time or timestamp in nanoseconds holds text only to the microsecond, which is what the parsers of extended_types read (L96), and a real number of seconds only to the double precision of its scaling, about 256 ns for current dates; integers are scaled exactly. Relevance: low; reviewer's confidence: high. (recorded)

Generated by Claude Code

…th `schema`

With `arrow = TRUE`, `dbColumnInfo()` names the types of a fetch of no rows, and knew only the formats of decided types.
For a result sent with `schema`, it failed with "Internal error: unexpected Arrow format".
`uint64` is now named like `int64`, and the other requested formats by the R type that the data frame fetch converts them to, named like the default path names it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A data frame fetch through Arrow converts a `uint64` column to `integer64` like an `int64` one.
nanoarrow wraps a value beyond `2^63 - 1` in that conversion, so `1e19` came back as `-8446744073709551616` and `2^64 - 1` as `-1`, without a warning and whatever `bigint` said.
The data frame fetch now rebuilds the chunks of such a column as doubles once one of its values is beyond, and keeps it a double in the later fetches of the execution, like the data frame path widens an integer column for a real.
No value is dropped, the double rounds it to 53 bits, and this covers the rows kept for a schema, whose storage classes an out-of-range warning could no longer name.
The stream holds the exact values as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
… a schema can request

With `arrow = TRUE`, `dbColumnInfo()` answers from the Arrow columns, and failed for requested formats until 9789588.
The test requests every type, every time unit and timestamps with and without a time zone, and checks that `dbColumnInfo()` names the R types of `dbFetch(rs, n = 0)` and of the full fetch, like the default path names them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

Brings in the busy mark reset through `R_ExecWithCleanup()`, the checks of Arrow parameters,
the 64-bit row counter and the UTF-16 text in binary columns, with the coercion warning of the layer below.

`get_column_names()` and `set_arrow_schema()` run their bodies through `run_guarded()`,
like the other guarded methods of `DbResult`, since `BusyScope` is gone.
`fetch_bytes()` reads text as UTF-8 for the requested `large_utf8` too,
and for text in any binary column, requested or not.
The result columns section keeps the note that a `schema` fixes the types up front
in the paragraph on `chunk_size`, which moved before the sentences on text.
`src/cpp11.cpp` is regenerated with both new entry points.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The merged test expected a coercion warning for the strings in a binary column,
but this branch reads text into a binary type silently, as its bytes, as `?"sqlite-arrow"` lists it.
The test keeps its check of the UTF-8 bytes on both paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

Brings in the bytes of a blob in a `utf8` column kept as they are, also in a UTF-16 database.
`fetch_bytes()` takes the new rule of the Arrow interface, which goes by the storage class:
a blob is read as a blob, everything else as UTF-8 text,
which covers the requested `large_utf8` and binary types as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

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.

The test of the requested types with 32-bit offsets reads its streams through `fetch_with_bytes_limits()`
instead of lowering the global limits,
and keeps checking every array with `ValidateFull()` through `arrow_validated()`,
as the `dbGetQueryArrow()` of these tests does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

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, the memory cleanup of the large tests with `helper-memory.R`, and the longjmp tests.
The requested types 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
…nt-tesla-mja103-schema

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.

`DbResult` keeps `set_arrow_schema()` next to the new parameters of `arrow_schema()` and `fetch_arrow()`.
The column builders keep the per-type functions of this branch,
where the merged change of the layers below, `std::isnan()` in the date and time branches, has no lines of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The builders of the requested date, time and timestamp types still used R's `ISNAN()`,
which the column builders no longer call, as an Arrow stream may be read on a thread other than R's main thread.
They now use `std::isnan()` like the rest of them.

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

`result_set_arrow_schema()` and `result_column_names()` are entry points on R's main thread that use a result,
like `result_fetch()`, which now first destroys the results that Arrow streams let go of on other threads.
They do so too, so that such a result does not keep its statement and read transaction open until another call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…nt-tesla-mja103-schema

Brings in the Arrow test fixtures moved into `helper-arrow.R`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
`query_formats()` and `expect_int64_bits()` move from the top of `test-arrow-schema.R` into `helper-arrow.R`, which `pkgload::load_all()` sources.
The wrappers that checked every array with `arrow_validated()` masked `dbGetQueryArrow()`, `dbReadTableArrow()` and `dbFetchArrowChunk()` in that file.
In the helper file they would mask them for every test file, so they move as `validated_dbGetQueryArrow()`, `validated_dbReadTableArrow()` and `validated_dbFetchArrowChunk()`, and the tests of `schema` call them by these names.
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

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

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 main. It will be closed once its replacements are merged.


Generated by Claude Code

krlmlr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Closed as superseded, as decided: the Arrow work is rebuilt from main as a chain of smaller pull requests, planned on #880. The data-frame path through Arrow that this stack carries (group D) is tracked in #881. The branch stays as a reference.


Generated by Claude Code

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