Repository navigation
Conversation
`dbSendQueryArrow()`, `dbGetQueryArrow()`, `dbFetchArrow()` and `dbFetchArrowChunk()` take a `schema` that requests the Arrow types of the columns, anything that `nanoarrow::as_nanoarrow_schema()` converts to a struct schema. Fields with names take the columns of those names, and the other columns are inferred; fields that all have empty names take all columns by position. The request is resolved and checked before the result is claimed and before any row is read, kept with the result for later fetches and executions, and replaced by a schema of a later fetch, which must match the types that the first chunk fixed. A requested type replaces int32 for integers that fit and `bigint`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… streams The result kept the children of the `schema` that the caller passed, which borrow from it, so releasing the schema left dangling pointers. It now keeps the checked types as Arrow format strings. A request was accepted while a stream of the execution existed but no chunk had fixed the types yet, and the stream and later fetches then fixed different types. While such a stream exists, a request must now be the one the stream reads with. Errors about `schema` have the class `RSQLite_error_schema` and the user's call, and a cleared result fails as without a schema. The read methods refuse unused arguments except DBI's documented `immediate`, and `dbReadTableArrow()` has RSQLite's own method that takes `schema`. The docs say that a column without a name is requested by position, and that positions are fixed when the types are requested. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The arrow package isn't a declared dependency, and R CMD check warned about its use in the tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… claude/rb-dbi-arrow-schema Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
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.
For users:
dbSendQueryArrow(),dbGetQueryArrow(),dbReadTableArrow(),dbFetchArrow()anddbFetchArrowChunk()get aschemaargument that requests the Arrow types of the result's columns, exposing the requested-types mechanism of #979 and #980. It takes ananoarrow_schemaof a struct type or anything thatnanoarrow::as_nanoarrow_schema()converts to one, such as a schema of the arrow package.dbReadTableArrow()now has RSQLite's own method (DBI's default droppedschema), and the read methods refuse arguments they don't use, as the write methods of #982 do, except DBI's documentedimmediate, which they accept and ignore. A requested type replaces the inference for its column, including #981's int32 for integers that fit,bigintand the declared type; the other columns are inferred as before. Documented in the new "Requested types" section of?"SQLiteResultArrow-class", with the argument in the Rd, an example and a NEWS bullet.Matching. #979 left the choice between positional and by-name matching and partial schemas to this item. As implemented: fields with names take the columns of those names, in any order, and the columns that no field names are inferred (a partial schema); fields that all have empty names take all columns by position, one field for each column; a schema with no fields requests nothing. Names match exactly, case-sensitively, as the names of the result's columns come back; a column named "" can only be requested by position (documented). Errors, all of class
RSQLite_error_schemawith the call of the user's DBI method (alsodbGetQueryArrow()anddbReadTableArrow()): a schema that isn't convertible or isn't a struct, fields with and without names mixed, a field name that occurs twice, a name that the result doesn't have (listing the result's columns), a name that the result has more than once (pointing to positional fields), a positional count mismatch, and a type that a column can't build (#979/#980's message, now naming the result's column number).When the checks run.
dbSendQueryArrow()resolves and checks the schema after preparing the statement but before it claims the result and before it bindsparams, so nothing is read and a refused schema leaves no open result; the column names come from the prepared statement (new internalresult_column_names()), and the types are checked by the new internalresult_check_arrow_request(), which builds the requested types and runsSqliteResultImpl::check_arrow_request()without claiming. The checked request is kept with theSQLiteResultArrow(newrequestslot, an environment) as Arrow format strings, not as the caller's schema, whose children only borrow from it (round 1 of the review found a use after free when the caller released the schema), and passed to every fetch, so it holds for later chunks, for streams, fordbColumnInfo(), for DBI'sdbFetch()on the Arrow result, and for new executions afterdbBind(). Aschemapassed todbFetchArrow()ordbFetchArrowChunk()replaces the kept request for this and later fetches; once the first chunk of an execution has fixed the types, it must request those types for the columns it names, per #979's rule, and while a stream of the execution exists before any chunk has fixed the types, it must request exactly the types that the stream reads with, for every column (round 1 found that a different request was accepted then, and the stream and later fetches fixed different types). A refused one leaves the result and the kept request as they were; a cleared result fails as without a schema. By-name fields become positions when the types are requested, so a statement that SQLite prepares again after a schema change takes them by position on a laterdbBind()(documented; the positional rule predates this PR).Internals. The internal fetches keep their positional struct schema. They also take the resolved request, a list of class
RSQLite_requested_typeswith one nanoarrow_schema, Arrow format string or NULL per column; NULL isAK_UNDECIDED, which the chunk sink already treats as "infer", so the int32 rule andbigintstill apply to those columns.check_arrow_request()now compares only the requested columns with the types the first chunk fixed, and its error names the column ("..., as for column 1 (x)."); with the streams of the execution (DbResult's counters) it also compares the request with the one in force. Request errors are a newArrowRequestError, whichresult_check_arrow_request()returns as a message for R to raise with its class; the two internal tests with that message are updated. Nullability and metadata stay ignored, as documented in #979.Tests in the new
tests/testthat/test-arrow-dbi-schema.R: by name in another order with inferred columns (chunk,dbFetchArrow(),dbGetQueryArrow()), names that aren't ASCII, by position, a schema with no fields, a schema frominfer_nanoarrow_schema()and from ananoarrow_vctr; every requested type family of #979 and #980 through the public API in one query (int8 to uint64, bool, null, float, double, utf8, large_utf8, binary, large_binary, date32, date64, time32 s/ms, time64 us/ns, timestamps in each unit with and without zones, durations) with exact values and NULLs, valid by nanoarrow's IPC round trip, and the same types from a stream; conversion warnings; a requested type overriding int32 andbigint = "character"while other columns keep them; later chunks past 65536 rows and new executions afterdbBind()keeping the request; a later fetch's schema replacing the request, refused for other fixed types (snapshot) without changing the row count, accepted for the fixed types of a column it didn't request; every error in a snapshot, run on a statement whose bind would fail, which shows that nothing is read, and leaving no open result; nullability and metadata ignored;dbColumnInfo()reporting the R types of requested types and keeping the first chunk; a stream with requested types read on a worker thread through #978's hook, with its warnings at the next call, and adbGetQueryArrow()stream on a worker with its warnings at release; a stream without and with a request refusing another request (both probes of the review) while the stream and later chunks read on, the same request passing, and a new execution after release; a schema released or moved by the caller after the request;dbReadTableArrow()with a schema and anId; unused arguments refused (snapshot) andimmediateaccepted; the error classes; a cleared result failing the same way with and without a schema. Under valgrind the test file and the review's probe of a released schema: 0 errors, 0 bytes definitely lost. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (thezh_TW.UTF-8locale is missing in the container), SKIP 64, PASS 14518 (#981: FAIL 0, WARN 3, SKIP 64, PASS 14239); the DBItest suites pass unchanged.R CMD check --no-manualon the built tarball (with vignettes, and_R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_=trueas in CI, which caught anarrow::call in the first version of the tests): 0 errors, 0 warnings, 1 NOTE (the worktree's .git file, included by the build).Decisions worth a look by the maintainer, implemented as described: by-name matching with partial schemas and positional matching only for schemas without any names (mixed refused); exact, case-sensitive name matching, although SQLite's identifiers are case-insensitive; a schema of a later fetch replacing the kept request for later fetches and executions rather than applying to that fetch only; and the kept request holding for new executions after
dbBind(), where the internal fetches infer anew unless requested again.Plan item 18, a layer of the rebuilt chain planned in #880; based on #982 (item 17). Not ported from an old PR: the old chain had no DBI methods.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code