Repository navigation
feat: Bind dates, times, timestamps, durations, half floats and dictionaries from an Arrow stream - #970
Draft
krlmlr wants to merge 8 commits into
Draft
feat: Bind dates, times, timestamps, durations, half floats and dictionaries from an Arrow stream#970krlmlr wants to merge 8 commits into
krlmlr wants to merge 8 commits into
Conversation
…onaries from an Arrow stream date32, date64, time32, time64, timestamp and duration parameters of any unit bind as reals, the very doubles that dbBind() binds for the Date, POSIXct, hms and difftime that nanoarrow converts them to: the value is converted to a double and multiplied by the same factor as in nanoarrow. A timestamp binds as an instant, whatever its time zone. Half floats bind as reals. A dictionary binds the value its index points to; the full validation of each array already checks the indices. Nested struct columns are still refused. The tests bind each type and unit both ways, with extended_types on and off, untyped and with the declared type of dbDataType(), and compare the storage classes and values. They also cover dictionaries, a round trip of the read path's temporal columns, and sliced struct arrays with sliced columns. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…o claude/rb-arrow-bind-types Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…o claude/rb-arrow-bind-types Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…o claude/rb-arrow-bind-types Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…a dictionary index out of range nanoarrow's ArrowHalfFloatToFloat() decodes subnormals wrongly, so half floats are now decoded as IEEE 754 binary16 in RSQLite. This deliberately differs from nanoarrow's conversion to R for subnormals. Dictionary indices are checked before the full validation, which named neither the parameter nor the row and read a uint64 index beyond INT64_MAX as negative. The tests add half floats by their bits, indices out of range in a later array, a dictionary of timestamps in milliseconds, a dictionary that changes between arrays, and restore a type that can't be bound in the test of reading a stream first. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… claude/rb-arrow-bind-types Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The half float and uint64 index tests failed on big-endian machines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
krlmlr
pushed a commit
that referenced
this pull request
Dec 1, 2026
As `arrow_int_array()` does since #970, so that the tests also hold on big-endian machines. 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.
No change of behavior for users: the internal
bind_arrow_stream()of #967 accepts more Arrow types, and no DBI method calls it yet.What changes
bind_arrow_stream()now binds date32, date64, time32, time64, timestamp and duration columns of every unit, with or without a time zone, half floats, and dictionary arrays. Before, they failed with "Can't bind parameter 1 of Arrow type …".The temporal types bind as reals, the very doubles that
dbBind()binds for the R vectors nanoarrow converts them to: date32 as days (Date), date64 and timestamp as seconds since the epoch (POSIXct, whatever the time zone), time32 and time64 as seconds since midnight (hms), duration as seconds (difftime in seconds). The value is converted to a double and multiplied by the same factor nanoarrow uses (1e-3, 1e-6, 1e-9). A division by the units per second rounds differently in the last bit for values such as 9 ms, 5 us or 3 ns, and the tests catch that.dbBind()itself ignoresextended_types: it binds a Date, POSIXct, hms or difftime as its bare double, so the storage class depends only on the declared column type, the same way for both paths.Half floats bind as reals, decoded as IEEE 754 binary16 in RSQLite: subnormals as their mantissa times 2^-24, infinities as infinities, and NaN as NULL, as SQLite binds any NaN. This deliberately differs from nanoarrow's conversion to R for subnormals:
ArrowHalfFloatToFloat()of nanoarrow 0.9.0 doesn't renormalize them, so 0x0001 converts to 1.1e-41 instead of 2^-24. A dictionary binds the value its index points to, with indices of any integer type, also for a sliced dictionary or a sliced index array, and also when the dictionary changes from one array of the stream to the next. A null index or a null dictionary value binds NULL. The indices of each array are checked before the full validation that #967 runs, so an index out of range fails before any row of that array runs with "Can't bind parameter 1 ($x) in row 2: the dictionary index 2 is out of range for 2 values.", with rows counted across the stream. A uint64 index beyond the range of int64 shows its unsigned value. An index in a child slot outside a sliced struct's rows, also a uint64 one of 2^63 or more, still gets nanoarrow's generic validation message. An out-of-range index in a null struct row is refused too, as nanoarrow's full validation does. When a later array of the stream fails this way, the rows of earlier arrays have already run, the same as for other errors in the middle of a stream. A dictionary of values that can't be bound, and nested struct columns, are still refused with the type error.Where the Arrow path can't match
dbBind()dbBind()binds its bare number (90 for 90 minutes), while nanoarrow converts a duration to a difftime in seconds, so a duration binds as seconds (5400).dbBind()of nanoarrow's conversion gives 5400 too.dbBind()gives for a factor. nanoarrow converts a dictionary of strings to character, anddbBind()binds that without a warning.dbBind()binds the same rounded double.Tests
In
tests/testthat/test-arrow-bind.R, every type and unit is bound both throughbind_arrow_stream()and withdbBind()of nanoarrow's conversion, with a NULL in between, negative values,extended_typesoff and on, and untyped and declared columns (the typedbDataType()gives). The tests comparetypeof()and the values, and check the exact doubles for untyped columns. Replacing the multiplication with a division makes them fail. There are also tests for half floats by their bits (0x0001, 0x03ff, 0x0400, ±0, ±inf, NaN), a duration against a difftime in minutes, a round trip of the int64, double, utf8, binary, date32, time64 and timestamp columns of the read path withextended_types, dictionaries (a factor with an unused level, every index type, null indices and values, a sliced array over a sliced dictionary, a dictionary of timestamps in milliseconds, a dictionary that changes between arrays, indices out of range in the first and a later array including a negative one and a uint64 one beyond 2^63, values that can't be bound), and sliced struct arrays with and without their own validity bitmap and with sliced columns, which #967 supports but didn't test.arrow_int_array()inhelper-arrow.Rnow builds small negative 64-bit values exactly, in native byte order. Two tests that used date32 as a type that can't be bound now use a nested data frame, since every type of RSQLite's read path now binds; in the test of reading a stream first, another result of the connection reads meanwhile, and the type error leaves it and the stream unread. The full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale warnings intest-encoding.R), SKIP 64, PASS 13423. valgrind (--leak-check=full) reports no errors and nothing lost fortest-arrow-bind.R.Layer F8b of the rebuilt chain, planned in #880; based on #967. Ported from #866 (temporal types, half floats, sliced struct tests) and the dictionary part of #867.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code