Repository navigation
Conversation
A value of another type, such as text, in an integer column was read with the 32-bit `sqlite3_column_int()`, keeping the low 32 bits of the 64-bit integer SQLite converts it to. Such a value now turns the column into integer64, as a stored 64-bit integer does, and reads the value `CAST(x AS INTEGER)` gives, saturated beyond 64 bits. The range check moves to `DbColumnDataSource` for the column storage to use. Closes #957. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Text in an integer column was converted to a 64-bit integer to check its range, and then once more by `fetch_int()` to store it. The value from the first conversion is now stored directly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The smallest 32-bit integer is `NA_integer_` in R, so it no longer counts as fitting in an R integer. A column holding it, as an integer or as text, turns into integer64 or as `bigint` asks. 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.
Closes #957.
When a column's first value is an integer,
dbFetch()coerces later values of another type into it. Text (or a blob) was read with the 32-bitsqlite3_column_int(), which keeps only the low 32 bits of the 64-bit integer SQLite converts the text to, so '5000000000' came back as 705032704 and '9223372036854775808' as -1, whateverbigintsaid.Now such a value is checked with
sqlite3_column_int64()first: if it needs more than 32 bits, the column turns into integer64 through the same storage spillover a stored 64-bit integer uses, andbigintthen applies as usual. The value is the oneCAST(x AS INTEGER)gives, including SQLite's saturation beyond 64 bits: '9223372036854775808' reads as 9223372036854775807. At the low end, '-9223372036854775809' saturates to the smallest 64-bit integer, which integer64 reads as NA, the same as for that integer stored as such. Text within the 32-bit range keeps the column integer, and the 64-bit value read for the check is stored directly, so the text is converted only once: reading 2,000,000 text values into an integer column takes about 0.27 s, against 0.33 to 0.36 s with a second conversion and 0.34 s onmainin the same runs. The usual "mixed type" warning still names the coerced type. I chose the promotion over NA with a warning because it is a contained change inDbColumnStorage::append_data()and matches how a stored 64-bit integer is handled; the 32-bit range check moves fromSqliteColumnDataSourcetoDbColumnDataSourceso the storage can use it.The range check now also counts -2147483648 as needing 64 bits: it is
NA_integer_in R, soSELECT -2147483648 AS xand the text '-2147483648' in an integer column used to come back as NA silently, onmaintoo. Such a column now turns into integer64, or asbigintasks, like any other value beyond the range of an R integer.Tested with a new test in
tests/testthat/test-basic-types.R, next to the mixed-type tests, covering positive and negative values beyond 32 bits, saturation at both ends,bigint = "numeric", and text within range. It fails onmain(the column comes back as integer 1, 705032704, -705032704, -1, 0, 12) and passes with the fix. A second test covers -2147483648 stored as an integer, alone and after another integer, and as text, and checks that -2147483647 stays integer; it fails before the fix (NA in an integer column) and passes with it. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (unavailable locale), SKIP 63, PASS 10717.This PR is independent of the Arrow chain planned in #880 and is based on
main. The chain's R5 layer (#952) refactors nearby code insrc/SqliteColumnDataSource.cpp; a trial merge into each layer of the chain merges the sources cleanly and conflicts only inNEWS.md, so the later merge into the chain needs a small resolution there.Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code