Repository navigation
Conversation
`SqliteColumnDataSource` parses the text of DATE, TIME, DATETIME and TIMESTAMP columns with `extended_types = TRUE` in the static `parse_date()`, `parse_time()` and `parse_datetime_local()`, which return whether the text could be parsed instead of warning, so that the Arrow arrays of the next commit can parse the same text without the warning. They parse into whole days and microseconds, which `fetch_date()`, `fetch_time()` and `fetch_datetime_local()` scale as before, and raise the same warnings for text they can't parse and for blobs. New tests pin the exact values and the warnings of the data-frame path for these columns, and that a warning made an error completes the result; they pass before and after this change. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
With `extended_types = TRUE`, a column declared as DATE, TIME, DATETIME or TIMESTAMP becomes a `date32`, `time64[us]` or `timestamp[us, UTC]` array in `result_fetch_arrow_chunk()`, whatever its values, as the data-frame path reads it as Date, hms or POSIXct in UTC. The declared types match as `datatype_from_decltype()` matches them for the data-frame path. Values are read as the data-frame path reads them. Text goes through the parsers of the previous commit, into days or whole microseconds. A number is a count of days, truncated toward zero, or of seconds, rounded to the nearest microsecond. A blob, text that can't be parsed, a count of days beyond the range of `date32`, a number of seconds beyond the range of int64 microseconds, and a time outside the day that `time64` holds are NULL, where the data-frame path warns, wraps the days in 32 bits, or keeps the duration. Rounding a time before midnight stops at the last microsecond of the day. None of these conversions is reported yet. Without `extended_types`, these columns follow their values as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Conflicts were adjacent additions, both sides kept: `value_text()` and `text_real()` next to `append_date()` and `append_time()` in `src/SqliteArrowColumn.cpp` and `.h`, and `fetch_arrow_chunk_out_of_memory()` next to `arrow_micros()` and `fetch_arrow_all()` in `tests/testthat/helper-arrow.R`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…claude/arrow-date-columns Takes the CI auto-update, 2e3606e, pushed to the branch on top of 229c74a. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The CI's auto-update regenerated `src/SqliteResultImpl.dd` and `src/cpp11.dd` with GCC, whose dependency output indents continuation lines by one space, which the filter in `src/Makevars.deps` does not drop, so the files gained hundreds of absolute and vendored paths (#836). This restores them as they were and keeps the auto-update's formatting of `src/SqliteResultImpl.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
Review of this pull request at 229c74a, by a Claude Code reviewer with clean context that read the description, both commits (1d77e80 and 229c74a) against #860 at 689a5c5, the code around them ( What was run
What holds
HighNone. Medium
Low
Generated by Claude Code |
…actly `append_date()` and `append_time()` read text through `value_text()` of #860, so that a conversion of text that runs out of memory fails the chunk at once, as for the other columns, instead of becoming NULL. `fetch_arrow_chunk_out_of_memory()` takes setup statements and `extended_types`, and a new test runs it on DATE, TIME and TIMESTAMP columns whose text is computed as it is read. Reals are rounded to microseconds with `std::nearbyint()`, to the nearest integer, halves to even in the default rounding mode. `std::floor(x * 1e6 + 0.5)` rounded an odd count between 2^52 and 2^53 one up, such as `5000000000.000001` seconds, where the count is exact and adding 0.5 makes a tie. `std::llround()` would round halves away from zero, but is unspecified for an infinity or a value beyond 64 bits, which the range check after rounding handles as it is. The tests pin that example, its negative, and two exact halves, and the dates that `dbFetch()` makes of huge and infinite reals in a DATE column, which the Arrow array holds as NULL. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Conflicts kept both sides: the declaration of `text_real(int column_type)` next to `append_date()` and `append_time()` in `src/SqliteArrowColumn.h`, and in `fetch_arrow_chunk_out_of_memory()` the setup statements and `extended_types` next to the returned value of column `x`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
Review of the fixes in this pull request at cfba409 (the commits since 229c74a), by a Claude Code reviewer with clean context that read the description, the merge c3518d3 of #860 at 3ac16c6 (its remerge diff, and each side's changes compared line by line), the merge 3c6c68c of the CI's formatting commit, the restored What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
`append_time()` rounded the seconds of a real times 1e6 with `std::nearbyint()`. The product is itself rounded to a double, a multiple of 1/4 µs for present-day timestamps, so about one in eight came out one microsecond off the nearest, such as `1759618878.0778434`, read as …844 where the double holds …843.4. It now splits the seconds with `std::modf()` into whole seconds and their fraction, both exact, and rounds only the fraction, halves to even in the default rounding mode, as CPython's `datetime.fromtimestamp()` does. The whole seconds are range-checked before their cast, and the sum stays within the int64 microseconds but their smallest value, which bit64 reads as NA, as the integer path does: a real of -9223372036854.775808 s gave exactly -2^63 µs before. The tests pin three present-day timestamps that the former rounding missed, exact halves (0.0078125 and 0.0234375 s) in place of 0.0000025 and 0.0000035 s, which are no halves as doubles, and the double nearest to -2^63 µs with the next one down, which is NULL. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Superseded: Accepted limitationsSuperseded by the new copy. Two review rounds: the first confirmed that the parser refactor leaves
Generated by Claude Code |
The CI's auto-update regenerated `src/SqliteArrowColumn.dd` and `src/cpp11.dd` with GCC, whose dependency output indents continuation lines by one space, which the filter in `src/Makevars.deps` does not drop, so the files gained hundreds of absolute and vendored paths (#836). This restores them as they were at 5465c7b and keeps the auto-update's formatting of `src/SqliteArrowColumn.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Question: should the Arrow arrays hold the values that
|
Question: should this pull request report the values that it turns into
|
Accepted limitationsTwo review rounds: the first confirmed that the parser refactor leaves
Found here, but on
Generated by Claude Code |
Sixth step of the Arrow rework (plan: #829 (comment)): with
extended_types = TRUE, the internal Arrow engine of #860 buildsdate32,time64andtimestamparrays from columns declared as DATE, TIME, DATETIME or TIMESTAMP. The entry pointresult_fetch_arrow_chunk()stays internal, so nothing changes for users.Commits:
SqliteColumnDataSourcegets the staticparse_date(),parse_time()andparse_datetime_local(), which parse the text of these columns into whole days or microseconds and return whether they could, instead of warning.fetch_date(),fetch_time()andfetch_datetime_local()call them, scale the result as before (static_cast<double>(days)andmicros * 1e-6) and raise the same warnings for text they can't parse and for blobs. feat: Report coerced values once per chunk ordbFetch(), with their rows #800 (ef68461) split the same functions into members that read the current value and return seconds; parsing text into integers instead lets the Arrow path keep every microsecond, so it needs no second copy of the boost calls, as the old stack'sparse_micros()had (2e62ede in feat: Request Arrow types for result columns withschema#801).extended_types. The Arrow handling of feat: Implement the DBI Arrow interface natively #795 (43db19f) with its refinements up to 3436358, read from the type rules at the top of34363581:src/SqliteArrowColumn.h.src/SqliteResultImpl.cpp, and a commit that restores the.ddfiles it filled with absolute paths (Incremental builds miss changes to bundled extensions undersrc/vendor/extensions/#836).What changes:
extended_types = TRUE, a column declared as DATE, TIME, DATETIME or TIMESTAMP isdate32,time64[us]ortimestamp[us, UTC]from the start, whatever its values, as the data-frame path reads it asDate,hmsorPOSIXctin UTC. The declared types match throughdatatype_from_decltype()of the data-frame path, made public for this, so both paths agree on names such asdatetime(they match the whole name, case-insensitive:DATETIME(6)is not one). A column of onlyNULLtakes these types too, also in a result of no rows. Expressions and other declared types follow the value-based rules of feat: Build Arrow arrays from text and blob columns #860.value_text(): a conversion that runs out of memory fails the chunk at once, as for the other columns, instead of becomingNULL.dbFetch().dbFetch()keeps, as CPython'sdatetime.fromtimestamp()rounds it:std::modf()splits it into whole seconds and their fraction, both exact, and only the fraction is rounded, withstd::nearbyint(), halves to even in the default rounding mode, which R keeps. Rounding the seconds times 1e6 rounds twice, since the product is rounded to a double first, a multiple of 1/4 µs for present-day timestamps: feat: Implement the DBI Arrow interface natively #795'sstd::floor(x * 1e6 + 0.5)andstd::nearbyint(x * 1e6)(cfba409) missed the nearest microsecond of about one present-day timestamp in eight (1759618878.0778434gave …844 where the double holds …843.43), and the former also rounded an odd count between 2^52 and 2^53 one up (5000000000.000001gave …002).std::llround()would round halves away from zero, and is unspecified for an infinity or a value beyond 64 bits. The whole seconds are range-checked before their cast, and the sum stays within the int64 microseconds but their smallest value, which bit64 reads asNA, as for an integer: a real of -9223372036854.775808 s gave exactly -2^63 µs at cfba409. The tests pin three present-day timestamps that the product missed, the 2^52 example and its negative, the exact halves 0.0078125 s and 0.0234375 s (7812 and 23438 µs), and the double nearest to -2^63 µs (…775391 µs) with the next one down (NULL).NULLtakes the place of a blob and of text that can't be parsed, wheredbFetch()warns and returnsNA, and of values beyond the range of the Arrow type:dbFetch()reads withsqlite3_column_int()and wraps; here it is read in full (b99d110);sqlite3_column_int()saturates at 64 bits before keeping the low 32:dbFetch()reads1e300and9e999as 1969-12-31 and-9e999as 1970-01-01, without a warning;[00:00:00, 24:00:00), such as86400,-1or'25:00:00', whichtime64can't hold and Arrow's full validation rejects;dbFetch()keeps such durations ashms. Rounding a number just below midnight stops at the last microsecond of the day (ca06a58).extended_types, these columns follow the value-based rules as before: text isutf8, numbersint64ordouble, and a column of onlyNULLtakes thedoubleof NUMERIC affinity.The data-frame path is unchanged. New tests in
test-extendedTypes.Rpin its exact values, the order and text of its warnings, and that a warning made an error completes the result; they pass on #860 and after each commit. Two of the pinned values, the time and the timestamp of the last row, differ betweenmicros * 1e-6andmicros / 1e6, so the pin catches a change of the formula (checked by mutation).The shared parser has quirks that this pull request keeps on both paths, and the tests pin them, since the Arrow arrays must read what
dbFetch()reads: it knows noTbetween date and time, noZ, no+02:00and noUTC(allNAorNULL); a timestamp needs a time; a date ignores anything after a space that follows the day; years run from 1400 to 9999. It also misreads a negative UTC offset, without a warning, onmaintoday and so on both paths here: boost's tokenizer splits on-and takes the fields after the seconds for the fraction of a second.'2024-01-02 12:00:00-02:00'reads as 12:00:00.02 (-05:30and-0500as .05 s),'2024-01-02 12:00-02:00'as 12:00:02, and after a fraction ('2024-01-02 12:00:00.5-02:00') the offset is dropped; TIME columns read'12:00:00-02:00'the same way. The instant is off by the whole offset. The tests pin the first shape in bothtest-extendedTypes.Randtest-arrow-dates.Ras behavior shared withdbFetch(); fixing the shared parser, for both paths at once, is left to a separate pull request.Deliberately left out:
NULLvalues once per chunk with their rows is pull request 7.date64,time32or other units and time zones, are pull requests 13 and 14.Tested:
tests/testthat/test-arrow-dates.R: each declared type with ISO text, month names, numbers (days, Unix seconds, reals, Julian days), fractional seconds from one to nine digits, time zones and offsets in timestamps under a session time zone that is not UTC, dates and timestamps from 1400 to 9999 with 1969, 1900 and 2038 around them, values beyond the range of each Arrow type and infinities, blobs and text that can't be parsed (invalid month and day, empty text, a year before 1400, a timestamp without a time),NULLand all-NULLcolumns, a result of no rows, text, numbers, blobs andNULLmixed in one column fetched in chunks of all rows, of 1 row up to one past the end, and of 2, 3 and 4 rows, a rebound statement, declared names in other cases and with a size, aliases and expressions, a UTF-16 database, andextended_types = FALSE. Where the rules agree, each chunk is compared withdbFetch()on the same connection in the same chunk sizes, with the values converted to the same instants, and withdbHasCompleted()anddbGetRowCount()after each chunk; exact microseconds are compared asinteger64.fetch_arrow_chunk_out_of_memory()takes setup statements andextended_typesfor it. It passes against an installed build and fails withoutvalue_text(); underload_all()it skips, as feat: Build Arrow arrays from text and blob columns #860's does, since the callr session loads another RSQLite.tests/testthat/helper-arrow.R:arrow_values()convertsdate32,time64andtimestamptoDate,hmsandPOSIXctin UTC,expect_same_chunks()takesunparsable = TRUEwheredbFetch()warns of values it can't convert, and the newarrow_micros()andfetch_arrow_all()read exact microseconds and fetch a whole result. Every chunk passesexpect_valid_chunk(), nanoarrow's full validation.ValidateFull()accepts all 29 chunks thattest-arrow-dates.Rbuilds underload_all(), and all 124 chunks of the three Arrow test files (arrow is not a test dependency here). It rejects atime64of 24:00:00, which nanoarrow's validation accepts, so the range oftime64is checked explicitly in the tests.time64, without the stop at the last microsecond of the day, with either former rounding, or reading days withsqlite3_column_int(), one or two blocks fail; withoutextended_typesreaching the Arrow column, all blocks but the one withextended_types = FALSEand the callr one fail.test_that()block oftest-arrow-dates.R,test-arrow-columns.R,test-arrow-text.Randtest-extendedTypes.Rpasses on its own in a fresh session right afterpkgload::load_all().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).-O1),test-arrow-dates.R,test-extendedTypes.R,test-arrow-columns.R,test-arrow-text.R,test-read-ahead.R,test-dbSendQuery.R,test-dbClearResult.R,test-error.Randtest-dbBind.Rpass without a report, and so does a script with chunks of several sizes over dates, times and timestamps from text, numbers, blobs, infinities and values out of range, rebinding, and arrays converted after their result was cleared and the connection closed, also undergctorture(TRUE).R CMD check --no-manual --no-tests --ignore-vignetteson a built tarball:Status: OK.src/SqliteArrowColumn.ddgains the three package headers it now includes, written by hand, since the build adds absolute system paths to it (Incremental builds miss changes to bundled extensions undersrc/vendor/extensions/#836).Timing at 229c74a, one million rows in one chunk from a file database, median of nine runs, three rounds with the same result, on an
-O2build:2023-11-14 22:13:57.123): 0.70 s for the Arrow chunk, 0.94 s fordbFetch().dbFetch().dbFetch()takes the same time as on feat: Build Arrow arrays from text and blob columns #860 within 1 to 3 %, which is the spread between rounds. The Arrow chunk of text takes 0.11 s on feat: Build Arrow arrays from text and blob columns #860, where it staysutf8: the boost parser is most of the cost on both paths.Sits on #860, which is on #859, #857, #856, #855, #830 and #850, and merges #845.
Size
About 260 hand-written lines of C++: 175 in
SqliteArrowColumn.cppand.h, 85 inSqliteColumnDataSource.cppand.h, of which about 40 move the existing parsing into the new functions, and 6 inSqliteResultImpl.cpp. Tests add about 480 lines: 360 intest-arrow-dates.R, 80 intest-extendedTypes.Rand 40 inhelper-arrow.R.Review
Two review rounds (first, second) led to cfba409 and 5465c7b; see the accepted limitations.
https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Generated by Claude Code