Repository navigation
Conversation
…k, with their rows The Arrow columns of #859, #860 and #861 convert values that don't fit their type, or make them NULL, without a trace. Each column now logs them in a `CoercionLog`, by storage class and what happened, with their count and the first five row numbers in the result, counted as `dbGetRowCount()` counts. Once the chunk is complete and the fetch loop has returned, `result_fetch_arrow_chunk()` raises one warning of class `RSQLite_warning_coercion` for them through `warn_coercion()` in R, which carries the logs in its `coercions` field. The warning comes while the busy guard still holds the result, so that a handler can't clear it between building the chunk and handing it out. The chunk is kept in the result until it is handed out: if the warning exits, as with `options(warn = 2)` or a handler that signals an error, the next fetch hands it out without warning again, and until then `dbGetRowCount()` leaves its rows out, `dbHasCompleted()` is false and `dbFetch()` refuses. A new bind drops it. The design follows #800 (ef68461) for the Arrow path only; the warnings of the data frame path are unchanged. Fetches that convert values in the existing Arrow tests now expect the warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…eports The base now keeps nanoarrow out of `SqliteResultImpl.h`, so the chunk kept for the next fetch is held behind the forward-declared `KeptArrowChunk`. Text and blobs that an open `int64` column saturates take their reading as reals when a real widens the column, so the log moves them from out of range to converted. A value that runs out of memory fails its chunk, which discards the log with it. The fetches of the base's new tests that convert values expect the warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…eports An open `int64` column now keeps the reading as a real only for text and blobs where it differs, which includes every value beyond `int64`, so the log still moves those from out of range to converted when a real widens the column. The log notes a value only once it has been read, after any out-of-memory error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
Review of this pull request at a5442bd, by a Claude Code reviewer with clean context that read the description, the diff against #861 at 6d490fb (the feature commit 855ab08 and the merges 98c0a09 and a5442bd), the code around it ( What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
…row order The review of #862 found four Low points. `warn_coercion()` builds the condition and signals it with `warning()`, with the same class, `coercions` field and message: through `rlang::warn()` each warning took about 0.4 ms, now about 0.05 ms, so that two million rows with conversions in chunks of 1000 take 0.30 s instead of 1.1 s, against 0.17 s without the report. The bullets are `*` everywhere, as rlang drew them without cli. A group of values beyond `int64` merged into the converted group when a real widens the column takes the slot of the earlier of the two, so that the groups stay in the order of their first rows. A `binary` column logs a value only after reading it, as the other columns do. The comments of `result_fetch_arrow_chunk()` and `fetch_arrow_chunk()` say that a kept chunk comes whole, whatever `n`, and the test of `options(warn = 2)` pins its length. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Superseded: Accepted limitationsSuperseded by the new copy. The clean review found nothing above Low: no row is lost or duplicated with
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Moved: should an Arrow chunk whose warning exits be kept for the next fetch, rather than end the result?Moved to #880: #880 (comment). Please answer there. When the coercion warning of a chunk ends in an error ( library(DBI)
con <- dbConnect(RSQLite::SQLite())
dbExecute(con, "CREATE TABLE t (id INTEGER, x)")
#> [1] 0
dbExecute(con, "INSERT INTO t VALUES (1, 1), (2, 2), (3, 'three'), (4, 4), (5, 5)")
#> [1] 5
res <- dbSendQuery(con, "SELECT x FROM t ORDER BY id")
fetch_chunk <- function(n) {
nanoarrow::convert_array(RSQLite:::result_fetch_arrow_chunk(res@ptr, n))$x
}
# The warning about the text in row 3 becomes an error
options(warn = 2)
try(fetch_chunk(4))
#> Error : (converted from warning) Values converted to the Arrow type of 1 column:
#> * Column `x` (int64): 1 text value converted (row 3)
# The chunk is kept: its rows don't count yet, and dbFetch() refuses
dbGetRowCount(res)
#> [1] 0
dbHasCompleted(res)
#> [1] FALSE
try(dbFetch(res))
#> Error : Can't fetch a data frame before the Arrow chunk that was kept when the warning about its values exited.
# The next fetch hands out the kept chunk whole, whatever its n
fetch_chunk(1)
#> [1] 1 2 0 4
fetch_chunk(1)
#> [1] 5
dbHasCompleted(res)
#> [1] TRUE
dbClearResult(res)
dbDisconnect(con)Created on 2026-11-13 with reprex v2.1.1
Kirill decides. If nobody decides, the chunk is kept, and #864's stream relies on it to go on after such an error. Generated by Claude Code |
Question: should the coercion warning cost less for small chunks?The warning comes once per chunk with conversions and costs about 0.05 ms, built and signalled with base R's
Kirill decides. If nobody decides, the cost stays as it is. Generated by Claude Code |
Question: should
|
Question: should the first Arrow chunk see the storage classes of a row that a data-frame read has converted?A data-frame fetch reads the next row ahead. If library(DBI)
fetch_chunk <- function(res, n = -1L) {
chunk <- RSQLite:::result_fetch_arrow_chunk(res@ptr, n)
nanoarrow::convert_array(chunk)$s
}
con <- dbConnect(RSQLite::SQLite())
dbExecute(con, "CREATE TABLE t (i INTEGER, s)")
#> [1] 0
dbExecute(con, "INSERT INTO t VALUES (1, 'a'), (2, x'626262'), (3, 'c')")
#> [1] 3
# A data-frame fetch of row 1 reads row 2 ahead; the blob in row 2 makes
# `s` binary in the first chunk, which reports the text in row 3
res <- dbSendQuery(con, "SELECT s FROM t ORDER BY i")
dbFetch(res, 1)$s
#> [1] "a"
fetch_chunk(res)
#> Warning: Values converted to the Arrow type of 1 column:
#> * Column `s` (binary): 1 text value converted (row 3)
#> <blob[2]>
#> [1] blob[3 B] blob[1 B]
dbClearResult(res)
# dbColumnInfo() in between reads row 2 as text, which converts the blob:
# the first chunk takes it for text, makes `s` utf8, and reports nothing.
# Expected: the same binary chunk and warning as above
res <- dbSendQuery(con, "SELECT s FROM t ORDER BY i")
dbFetch(res, 1)$s
#> [1] "a"
info <- dbColumnInfo(res)
#> Warning: Column `s`: mixed type, first seen values of type string, coercing
#> other values of type blob
fetch_chunk(res)
#> [1] "bbb" "c"
dbClearResult(res)
dbDisconnect(con)Created on 2026-11-13 with reprex v2.1.1
Kirill decides. If nobody decides, it stays as it is, recorded in #863's code comment. Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the copy of 2026-11-29. The clean review found nothing above Low: no row is lost or duplicated with
Found here, but on
Generated by Claude Code |
…eports Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
…eports Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
…eports Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
…eports Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R
Question: should an integer that a double column can't hold exactly be reported as converted?The clean review of 2026-11-29 rated this Medium. An integer in an Arrow column of type double is never reported, on the premise that library(DBI)
con <- dbConnect(RSQLite::SQLite())
q <- "SELECT 9007199254740993 AS x UNION ALL SELECT 1.5"
dbGetQuery(con, q)$x
#> Warning: Column `x`: mixed type, first seen values of type integer64, coercing other values of type real
#> integer64
#> [1] 9007199254740993 1
res <- dbSendQuery(con, q)
ch <- RSQLite:::result_fetch_arrow_chunk(res@ptr, -1L)
sprintf("%.0f", nanoarrow::convert_array(ch$children[[1]], double()))
#> [1] "9007199254740992" "2"
# no warning: the first value changed unreported (the second is 1.5, printed with "%.0f")Counting such a value as converted, when
Kirill decides. The fix was not written in this session: the session's harness refused to start the agent that would have written it. If nobody decides, it stays as it is, listed as an accepted limitation. Output from a run of this session with Generated by Claude Code |
Accepted limitationsThe clean review found nothing above Low: no row is lost or duplicated with The clean review of 2026-11-29, after
Found here, but on
Generated by Claude Code |
…chunk A result fetched as Arrow arrays refuses every data frame fetch, so the refusal for a kept Arrow chunk no longer applies. The tests fetch only Arrow chunks from their results. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Seventh step of the Arrow rework (plan: #829 (comment)): the internal Arrow engine of #859, #860 and #861 now reports the values it converts to the type of their column, or makes
NULL, with one warning per chunk. The entry pointresult_fetch_arrow_chunk()stays internal, so nothing changes for users.What changes:
SqliteArrowColumnlogs every value that feat: Build Arrow arrays from the integer, real and NULL columns of a result #859, feat: Build Arrow arrays from text and blob columns #860 and feat: Build Arrow date, time and timestamp arrays withextended_types#861 convert silently, in a newCoercionLogper column: grouped by storage class and what happened, with the count and the first five row numbers. Row numbers count from 1 across the whole result, asdbGetRowCount()counts rows, so a chunk after a data-frame fetch goes on from the rows of that fetch. Logging calls no R API. The groups:int64column fixed by the first chunk, text and blobs read as numbers, numbers rendered as text, text in abinarycolumn, and a blob of valid UTF-8 in autf8column. This includes values of another storage class within the first chunk, after the first value has decided the type. Text and blobs that an openint64column reads as beyond its range take their reading as reals when a real widens the column later in the chunk (feat: Build Arrow arrays from text and blob columns #860), and the log then counts them as converted.NULLinstead: a real, or the leading integer of text or a blob, beyondint64; a count of days beyonddate32; seconds beyondint64microseconds, or an infinity; a time outside the day, as a number or as text.NULLinstead: text and blobs in autf8column.NULLinstead: text that isn't a date or time, and any blob, in a date or time column.Not reported, since
dbFetch()reads them the same way without a warning: integers in adoublecolumn, integers widened todoublewithin the first chunk, and numbers within the range of a date or time column.Once the chunk is complete,
SqliteResultImpl::fetch_arrow_chunk()hands the logs towarn_coercion()in the newR/warn-coercion.R, which raises one warning of classRSQLite_warning_coercionwith a line per column, and carries the logs in itscoercionsfield:The warning is raised after
fetch_loop()has returned and the struct array is assembled, never while values are read: no R code runs while a chunk is half-built, and an error made of the warning doesn't pass the handler of the fetch loop, which ends the result. It is raised while the busy guard of fix: Never restart a statement after an error indbFetch()ordbBind()#830 still holds the result: a handler can readdbGetRowCount()anddbHasCompleted(), while fetching from, binding or clearing the result fails with the guard's error, such as "Can't clear a result while one of its fetches or binds is running, as from a handler of a warning that it raised." Raising it from R after the entry point has returned would let a handler clear the result between building the chunk and handing it out.The chunk stays in the result until it is handed out. When the warning exits instead of returning, because
options(warn = 2)turns it into an error ("(converted from warning) Values converted to the Arrow type of 1 column: ..."), a handler signals an error (the guard's included) or an exiting handler catches it, the error reaches the caller and the chunk is kept. The nextresult_fetch_arrow_chunk()hands it out without warning again, whole, whatever itsn: after a fetch of 100 rows whose warning failed, a fetch of 1 row returns those 100 rows. The fetches after it go on with the next rows, so no row is lost. Until then its rows don't count:dbGetRowCount()leaves them out anddbHasCompleted()isFALSE, so a loop untildbHasCompleted()gets them.dbFetch()refuses with "Can't fetch a data frame before the Arrow chunk that was kept when the warning about its values exited.", since its rows would come out before the earlier rows of the kept chunk, anddbBind()drops the kept chunk with the rest of the execution. The same counting holds while a handler runs.Each chunk starts with empty logs, so a fetch that fails after converting values (a step error, an interrupt) doesn't report them with the next fetch. A value that runs out of memory while it is read is an error that fails its chunk (feat: Build Arrow arrays from text and blob columns #860, feat: Build Arrow date, time and timestamp arrays with
extended_types#861), not a conversion: the log notes a value only after reading it, and goes with the failed chunk.The simpler alternative, for the maintainers to choose: raise the warning inside the
tryof the fetch loop, so that a warning that exits ends the execution, as an error ofdbFetch()does, with its warning turned into an error byoptions(warn = 2). That dropsKeptArrowChunkand its special cases incomplete(),n_rows_fetched(),fetch()andbind(), about 50 lines with their tests, and thenof a fetch would always hold. The cost: the rows of the chunk are lost, and so are the remaining rows of the result, so that withoptions(warn = 2)the first chunk with a conversion ends the read. The open question of mixing data-frame and Arrow fetches on one result may settle it too.SqliteResultImpl.hkeeps nanoarrow out, as feat: Build Arrow arrays from the integer, real and NULL columns of a result #859 has it: the kept chunk lives behind the forward-declaredKeptArrowChunk, defined inSqliteResultImpl.cpp.The design comes from #800 (ef68461:
CoercionLog,R/warn-coercion.R), with its refinements 7f6a01e (the log of a failed fetch is discarded), 1fcf5a4 (row numbers in full), 4a4e580 (values of the null type reported as dropped) and a5f157a (rlang::warn()withoutcall), applied to the Arrow path only. Where it differs:dbFetch(), with their rows #800 warned inside the fetch, before handing out the chunk, so that an error made of the warning released the chunk with its rows; here the chunk is kept, and the warning comes after the fetch loop.dbFetch(), with their rows #800 kept the first 20 and the last two row numbers per group and formatted them with cli when installed, throughrlang::warn(); here the first five and..., with*bullets, joined and signalled with base R.NULL, as the Arrow arrays hold it, where feat: Report coerced values once per chunk ordbFetch(), with their rows #800 saidNA, and "text" for the storage class feat: Report coerced values once per chunk ordbFetch(), with their rows #800 called "string". feat: Report coerced values once per chunk ordbFetch(), with their rows #800's text for worker threads (coercions_text()) is left out.The data-frame path is unchanged:
dbFetch()keeps its "mixed type" and date warnings exactly as they are, raised while it reads. Extending the per-fetch report todbFetch()would be a separate, user-visible change, also for the data frames that pull requests 19 and 20 build through Arrow, for which #800 warned once perdbFetch().Deliberately left out:
get_next().dbFetch(), with their rows #800 has it in c7327be.intand has no hook to set the count (fix: Count rows in 64 bits, so thatdbGetRowCount()anddbGetRowsAffected()stay right beyondINT_MAX#858 adds both). The logs take row numbers asint64_t, computed in 64 bits from the count, and R formats them as doubles; the test formats numbers beyond 2^31 directly.Tested:
tests/testthat/test-arrow-coercion.Rwith a snapshot of the message (_snaps/arrow-coercion.md): several columns with several groups at once, and thecoercionsfield; one block per kind of conversion: reals truncated and values beyondint64, text beyondint64that a later real in the chunk turns into a converted real, the null type, text, blobs and numbers converted betweenutf8,binaryanddoublewith invalid UTF-8 and a NUL byte, and unparsable and out-of-range dates, times and timestamps; 30 values (the list shortened) and rows 100000 and 123456 in full, with numbers beyond 2^31 formatted directly; row numbers in later chunks and after adbFetch()in between;options(warn = 2): the error,dbGetRowCount(),dbHasCompleted()anddbFetch()meanwhile, the kept chunk handed out by the next fetch and the rest after it; a calling handler that muffles, which gets the chunk and sees the result busy; a handler that clears the result, refused by the guard, with the chunk kept; a new bind dropping a kept chunk; a step error after a converted value, not reported by the next fetch; and no warning when nothing is converted: widening within a chunk, integers in adoublecolumn,NULL, all-NULLcolumns and dates as numbers and text, in one chunk and in chunks of one row.tests/testthat/helper-arrow.R:fetch_arrow_chunk()andfetch_arrow_all()takeconverted = TRUEto expect the warning, andexpect_same_chunks()lets it through where it already allowsdbFetch()'s warnings (mixed = TRUE,unparsable = TRUE);warnings_of()andexpect_coercions()collect and check the warnings. The fetches intest-arrow-columns.R,test-arrow-text.Randtest-arrow-dates.Rthat convert values now expect the warning; their values are unchanged.test_that()block of the four Arrow test files andtest-extendedTypes.Rpasses on its own in a fresh session right afterpkgload::load_all(); the two out-of-memory blocks skip there, since theircallrsessions need an installed build.test-extendedTypes.Rpass, the out-of-memory blocks oftest-arrow-text.Randtest-arrow-dates.Rincluded.int64as out of range when a real widens the column, merging their rows out of order, or putting the merged group in the slot of the later one, keeping the log of a failed fetch for the next one, counting a kept chunk indbHasCompleted()ordbGetRowCount(), keeping it acrossdbBind(), lettingdbFetch()run before it, and numbering rows from the start of each chunk.extended_types#861's latest head: under AddressSanitizer (gcc,-O1),test-arrow-coercion.R,test-arrow-columns.R,test-arrow-text.R,test-arrow-dates.R,test-read-ahead.R,test-dbSendQuery.R,test-dbClearResult.R,test-error.R,test-dbBind.Randtest-extendedTypes.Rpass without a report, and so does a script with chunks of several sizes and conversions in every column; warnings turned into errors, refused by the guard and caught by exiting handlers; kept chunks handed out, dropped bydbBind(), bydbClearResult()and with the result afterdbDisconnect(); and chunks converted after their connection was closed, also undergctorture(TRUE).extended_types#861's latest head:devtools::test()withNOT_CRAN=true: no failures beyond the three errors intest-httpvfs.Rthat also happen onmain(test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837).extended_types#861's latest head:R CMD check --no-manualon a built tarball, with tests and vignettes andNOT_CRAN=true:Status: OK.DESCRIPTIONonly gainswarn-coercion.RinCollate, fromdevtools::document().Cost of a chunk without conversions, measured before the merge of #861's latest head, one million rows from a file database in one chunk, median of nine runs, three rounds alternating between #861 and this branch,
-O2:int640.083 to 0.087 s on #861 and 0.083 to 0.089 s here,double0.081 to 0.085 and 0.082 to 0.086,utf80.110 to 0.114 and 0.111 to 0.117, timestamps as text 0.67 to 0.72 and 0.69 to 0.73, the four columns together 0.89 to 0.91 and 0.88 to 0.91, and the four columns in 10000 chunks of 100 rows 1.09 to 1.11 and 1.09 to 1.12. Four more rounds of 21 runs gave 0.082 to 0.086 s forint64alone on both, and 0.137 to 0.140 against 0.134 to 0.139 s with adoublecolumn next to it. The differences stay within the spread between rounds: logging costs a row number and a comparison per value, and the R call happens only for a chunk with conversions.Cost of the warning, two million rows of an
int64column with text in every hundredth row, warnings muffled, median of five runs, three rounds: in chunks of 1000 rows 0.17 to 0.18 s on #861, 1.03 to 1.20 s throughrlang::warn()and 0.29 to 0.30 s now; in chunks of 10000 rows 0.14 to 0.16, 0.26 to 0.29 and 0.16 to 0.18 s; in one chunk 0.14 to 0.16 s on all three. One call ofwarn_coercion()takes 0.40 to 0.45 ms throughrlang::warn()and 0.045 to 0.050 ms now.Sits on #861, which is on #860, #859, #857, #856, #855, #830 and #850, and merges #845.
Size
About 395 hand-written lines of C++: 185 in the new
CoercionLog.cppand.h, 110 inSqliteArrowColumn.cppand.h, and 100 inSqliteResultImpl.cppand.h; 73 lines of R inR/warn-coercion.R; and 415 lines of tests: 350 intest-arrow-coercion.R, 50 inhelper-arrow.Rand 20 in the three other Arrow test files. That is about 880 in all, above the plan's 600. Most of it is tests, one block per case of the plan, and the logging, the warning and the kept chunk don't make sense without each other, so the pull request is kept whole. The.ddfiles are written by hand (#836).Review
The clean review found nothing above Low; its points are answered in ea9f836, and the design choice it raised is the first of the accepted limitations: uncheck it to switch to the simpler alternative.
https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Generated by Claude Code