Repository navigation
Conversation
An Arrow chunk now reads reals as double, and an int64 column widens to double when a real arrives in the same chunk. A column of NULL values takes the type of its declared affinity, int64 for INTEGER and double for REAL and NUMERIC, and the null type without a declared type. The first chunk of an execution fixes the column types for its later chunks, which convert the values that don't fit, without reporting them yet; dbBind() starts an execution that decides its types anew. Text and blob values still fail the chunk, as does a column of NULL values declared as TEXT or BLOB. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Question: keep values that arrive after the first chunk has typed their column as null?Carried over from #859's question, which nobody answered; this pull request ports #859's typing rules onto the row sink and implements the default described below (NULL, without a report until F4a reports conversions). The links below point at #859's lines. The first chunk of an execution fixes the Arrow types for its later chunks ( library(DBI)
con <- dbConnect(RSQLite::SQLite())
# A column without a declared type, NULL in the first chunk
res <- dbSendQuery(con, "
WITH t(i) AS (VALUES (1), (2), (3), (4))
SELECT CASE WHEN i > 2 THEN i END AS x FROM t
")
chunk <- RSQLite:::result_fetch_arrow_chunk(res@ptr, 2L)
nanoarrow::infer_nanoarrow_schema(chunk)$children$x$format
#> [1] "n"
# The later chunk keeps the null type: 3 and 4 become NULL without notice
# (expected: the values 3 and 4, or a warning)
nanoarrow::convert_array(RSQLite:::result_fetch_arrow_chunk(res@ptr, -1L))
#> x
#> 1 NA
#> 2 NA
dbClearResult(res)
dbDisconnect(con)
Kirill decides. If nobody decides, the rule stays as it is until #862, and the limitation stays checked in the "Accepted limitations". Generated by Claude Code |
The header of `SqliteArrowColumn` now states that the values that later chunks convert are not reported until the conversion reports (F4a) exist, and gives two examples. Tests pin both examples, so that F4a's change shows up as a test diff. Only integer and real values in a column of the null type become NULL: text still fails the chunk. More tests pin reals at the edges of int64 and the affinity of declared types such as FLOATING POINT and CHARINT. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Reals at -2^63 and just below 2^63 convert to int64, and the declared types of the affinity test are checked against dbFetch(). The comment on a column of the null type names the values that become NULL, as text fails the chunk. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
No change of behavior for users: Arrow chunks are still fetched only through the internal
result_fetch_arrow_chunk(), which no DBI method calls yet.This layer types the columns of an Arrow chunk from their values. A real becomes double, and an int64 column widens to double when a real arrives later in the same chunk; integers beyond 2^53 in magnitude become the nearest double. A column whose values in the first chunk are all NULL, also in a chunk of no rows, takes the type of its declared affinity as
dbFetch()does: int64 for INTEGER, double for REAL and NUMERIC (BOOLEAN has NUMERIC affinity), the null type without a declared type. The first chunk of an execution fixes the column types for its later chunks, which convert the values that don't fit: an integer in a double column becomes the nearest double, a real in an int64 column is truncated toward zero (NULL beyond the range of int64, infinities included), and any integer or real value in a column of the null type becomes NULL.dbBind()starts an execution whose first chunk decides the types anew. Text and blob values still fail the chunk, also in a column of the null type, as does a column of NULL values declared as TEXT or BLOB; F2a adds them.Limitation, by design for this layer: values change silently after the first chunk has fixed the column type, because none of these conversions is reported yet; the entry points are unexported until then. Two examples: in
CREATE TABLE t (c FLOATING POINT)(INTEGER affinity) with the rows NULL and 3.9, fetched as a chunk of one row and then the rest, the first chunk types the column int64 and the second gives 3; and an all-NULL first chunk of an untyped column or an expression such asSELECT CASE WHEN id > 1 THEN 2.5 ENDtypes it as the null type, so every later value becomes NULL. The header ofsrc/SqliteArrowColumn.hstates this, and tests pin both examples with their current values, so that the coercion reports (F4a) show up as a test diff. F4a will also cover the Medium finding from #862 that an integer a double can't hold exactly must be reported when an int64 column widens or an integer lands in a double column; a TODO insrc/SqliteArrowColumn.hmarks the spot.Open question carried over from #859, see #955 (comment): should values that arrive after the first chunk has typed their column as the null type become NULL? This PR implements #859's behavior, NULL without a report; the alternatives are to fail the chunk, or to widen the type in a later chunk, which breaks the fixed schema of a stream.
The design: a new
SqliteArrowColumn(ported from #859) builds the child array of one column and decides its type;SqliteArrowChunkSinkfrom #954 holds one per column, and the result keeps the types the first chunk fixed in a vector ofARROW_KIND(in its own header, so thatSqliteResultImpl.hdoesn't compile the nanoarrow headers), cleared bydbBind().Tests in
tests/testthat/test-arrow-column-types.Rcompare chunks withdbFetch()of the same rows on a separate result where the rules agree, and pin the rest: int64 edges (INT64_MIN/MAX, 2^53 ± 1) kept exactly in int64 columns and widened to the nearest double, mixed integer and real columns in one chunk and across chunks, reals in an int64 column fixed by an earlier chunk (2^63 and ±Inf become NULL, -0.0 and a denormal become 0, -2.5 becomes -2), the two silent conversions above, text in a column of the null type, an all-NULL first chunk with each declared affinity (INTEGER, REAL, NUMERIC, BOOLEAN, none, an expression, TEXT and BLOB) and with the declared types FLOATING POINT and CHARINT (int64), STRING, DOUBLE PRECISION and NUMERIC(10,2) (double), and VARCHAR (fails as text), and rebinding. The F1a tests that pinned per-chunk typing and failing reals now pin the new rules. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale warnings intest-encoding.R, as on the base), SKIP 63, PASS 11652.Layer F1b of the rebuilt chain, planned in #880; based on #954. Ported from #859 (draft).
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code