Repository navigation
Conversation
…bWriteTableArrow()` natively `dbAppendTableArrow()` inserts the rows of a stream with one prepared INSERT that binds the stream as `dbBindArrow()` does, in a savepoint, so that a failure part-way leaves the table unchanged. `dbCreateTableArrow()` types the columns as `dbCreateTable()` types the data frame that nanoarrow converts the schema to, except INTEGER for uint32, int64 and uint64. `dbWriteTableArrow()` creates, overwrites or appends as `dbWriteTable()` does, also in a savepoint. A stream with a type that the Arrow bind can't bind, such as a decimal, goes through DBI's default method inside the savepoint. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…claude/rb-dbi-arrow-write
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…claude/rb-dbi-arrow-write
`dbAppendTableArrow()` and `dbWriteTableArrow()` run in `with_savepoint()`. After a failure, also of the release, a savepoint that began the transaction is rolled back with ROLLBACK, which needs no lock, and nothing is rolled back once SQLite has ended the transaction itself, so the original error is raised. The fallback for types that the Arrow bind can't bind converts 64-bit integers to integer64, which keeps their values. `dbWriteTableArrow(overwrite = TRUE)` reads the stream first while a statement of the connection reads, before it drops the table. Savepoint names are numbered rather than random, the methods check that nanoarrow is installed, and rlang 1.0.0 is required. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…claude/rb-dbi-arrow-write
… original error The fallback for types that the Arrow bind can't bind fails for a uint64 value beyond the range of int64 with the bind path's error, naming parameter and row, instead of writing the wrapped integer64. A failed rollback is attached to the original error as `rollback_error` and a line of its message rather than raised as a warning, which `options(warn = 2)` made the error. The cleanup is registered before the SAVEPOINT, the fallback releases its stream also on failure, and savepoint ids are formatted without scientific notation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The fallback of `dbAppendTableArrow()` checks uint64 columns for values beyond INT64_MAX on the array itself, in C++ (`arrow_uint64_beyond_int64()`), before nanoarrow converts them to integer64, where 2^63 became NA and looked like a NULL. The fallback converts each column on its own, sliced as the struct array is, since nanoarrow 0.9.0 ignores the offset of a struct array when it converts it. A failed rollback is attached to an rlang error as a bullet of its body, which its message is formatted from. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Question: one more review round for the last fix in this pull request?The third and last review round of this pull request found a High in the fallback that writes Arrow streams with decimal columns through data frames: a
Kirill decides. Until then no further round runs, and the pull request stays a draft. Generated by Claude Code |
For users:
dbCreateTableArrow(),dbAppendTableArrow()anddbWriteTableArrow()now have RSQLite's own methods, so DBI's defaults, which converted each chunk of the stream to a data frame and appended it withdbAppendTable(), are no longer used for the usual Arrow types. The rows of the stream go into SQLite through one preparedINSERTthat binds the stream directly, with the Arrow bind path of #967–#971 thatdbBindArrow()uses since #981. NEWS bullet; the user documentation is the new section "Writing tables" of?"SQLiteResultArrow-class", with an example.dbCreateTableArrow()accepts a schema, a stream (which keeps its data), an array or a data frame, as DBI documents. The column types are those thatdbCreateTable()gives the data frame thatnanoarrow::infer_nanoarrow_ptype()makes of the schema, which is what DBI's default does, soextended_types = TRUEgivesDATEfor date32,TIMEfor time32/time64 andTIMESTAMPfor timestamp and date64, andREALwithout it. One deliberate difference: uint32, int64 and uint64 fields, also as dictionary values, areINTEGERinstead ofREAL, because the Arrow bind binds them as integers (#970), and aREALcolumn would turn integers beyond 2^53 into rounded reals. A test compares every type withdbCreateTable()of the ptype, with and without extended types.dbAppendTableArrow()names the stream's fields as the columns of theINSERT, so that a subset or another order of the table's columns works as DBI specifies, and binds the columns by position (new internalbind_arrow_columns(), split out ofbind_arrow_stream()), so that any field name works, including names that a named placeholder can't hold. It returns the number of rows inserted. A column that the table lacks fails when the statement is prepared, before the stream is read. While another result of the connection is reading, the stream is read to its end first (#967's rule), sodbAppendTableArrow(con, "t", dbReadTableArrow(con, "t"))inserts the rows that were there once. A stream with a field that the Arrow bind can't bind, such as a decimal, a string view or a nested type, goes through DBI's default method (callNextMethod()), so that it keeps working as before: decimals are written as reals through nanoarrow's data frames. The check uses the bind path's own type rule through a new internalarrow_schema_can_bind()in C++ (SqliteArrowParamSource::can_bind_column()), so the two can't drift apart.dbWriteTableArrow()creates, overwrites or appends asdbWriteTable()does: an existing table withoutappendoroverwriteis an error,append = TRUEcreates a missing table,temporaryapplies to a new table.Transactions. Each method runs in a savepoint, like
dbAppendTable()anddbWriteTable(): a stream that fails part-way, or a constraint violation in a later chunk, leaves the table and the database as they were, also foroverwrite = TRUEand inside a user's transaction, which keeps its own rows. This is a change from DBI's defaultdbAppendTableArrow(), which appended each chunk in its own call and kept the chunks before a failure; DBI's specification asks that "the remote table remains unchanged" on failure.Arguments. The methods refuse arguments in
...(rlang::check_dots_empty()), such asfield.typesorrow.names. DBI's defaults ignored most of them, and DBItest requiresdbCreateTableArrow(fields = )to fail, which the default did only by accident (a duplicate argument fordbCreateTable()).append,overwriteandtemporarymust beTRUEorFALSE, and the name must quote to one identifier. Errors carry the call of the DBI method.DBItest. The Arrow write tests (
arrow_create_table_arrow_*,arrow_append_table_arrow_*,arrow_write_table_arrow_*) all run with the native methods, FAIL 0, with the same 16 skips as on the base: six "Internal: Need to enhance test_arrow_roundtrip()" in DBItest itself and ten for thedate_typed,time_typedandtimestamp_typedtweaks that RSQLite sets toFALSE. No new skips.Tests in the new
tests/testthat/test-arrow-write.R: column types of every bindable type and a decimal againstdbCreateTable()of the ptype, with and without extended types; creation from a schema, a stream that keeps its data, an array and a data frame; values of each storage class round-tripping Arrow → SQLite → data frame and → Arrow, with thetypeof()stored; an int64 beyond double precision round-tripping exactly from RSQLite's own read path; NULLs, a null struct row and the null type; dictionaries of utf8 and of int64 values; dates, times and timestamps with extended types on and off, stored asdbWriteTable()stores the data frame and read back as date32/time64/timestamp; insertion by name, case-insensitive, with defaults for missing columns, row counts over several chunks and an empty stream; a column the table lacks failing before the stream is read; a stream of another connection failing at its fifth row (dbAppendTableArrow(),dbWriteTableArrow()appending, overwriting and creating) and a unique constraint in a later chunk, each leaving the table unchanged and no transaction open; streams of the same table fromdbReadTableArrow()anddbGetQueryArrow(), also with the first chunk read on another thread; a stream of another connection whose first chunk was read on another thread; quoting of table and column names (keywords, spaces, commas, quotes, backticks, newlines), quoted names,Id()andSQL(); temporary tables invisible to a second connection, also overwritten and appended; create/overwrite/append semantics and a zero-row stream; the decimal fallback, also failing in the savepoint; argument errors (snapshot) and a closed connection. Eachtest_that()block runs on its own afterload_all(). Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (thezh_TW.UTF-8locale is missing in the container), SKIP 64 (as on #981), PASS 14373 (#981: 14239). R CMD check --no-manual: 0 errors, 0 warnings, 1 NOTE (the worktree's .git file).Decisions worth a look by the maintainer, implemented as described:
INTEGERrather than DBI'sREALfor 64-bit integer fields; one savepoint per call instead of per chunk; DBI's default as the fallback for types the Arrow bind can't bind, rather than an error; refusing unused arguments in...rather than ignoring them.Plan item 17, a layer of the rebuilt chain planned in #880; based on #981 (item 16). Not ported from an old PR: the old chain had no DBI methods for writing.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code