Skip to content

feat: Build requested large, date64, time and timestamp arrays in any unit and time zone - #980

Draft
krlmlr wants to merge 5 commits into
claude/rb-arrow-requested-typesfrom
claude/rb-arrow-requested-temporal
Draft

krlmlr wants to merge 5 commits into
claude/rb-arrow-requested-typesfrom
claude/rb-arrow-requested-temporal

Conversation

@krlmlr

@krlmlr krlmlr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

No change of behavior for users: this extends the internal schema argument of the Arrow fetches (fetch_arrow_chunk_warn(), read_arrow_stream(), from #979) to more requested types. Besides the types of #979, a fetch can now request large_utf8, large_binary, date64, time32 in seconds or milliseconds, time64 in microseconds or nanoseconds, and timestamp and duration in any unit, a timestamp with any time zone or none. The requested types now carry their unit and time zone (ArrowColumnType in src/SqliteArrowKind.h), so a later request must match them too: timestamp[ms, UTC] after timestamp[ms, Europe/Vienna] is refused like any other type. Half float, decimals, intervals, views, dictionaries, nested and extension types still fail before any row is read.

large_utf8 and large_binary read values as utf8 and binary do, with the same warnings, but have no byte limit of their own: their 64-bit offsets address any chunk, so the number of rows that the fetch asks for (65536 per chunk for a stream by default) bounds the memory of their chunk, as it does for a data-frame fetch, and SQLite's length limit bounds each value. A chunk that memory can't hold fails with an error.

date64 is the days of date32 in milliseconds, read by the same rules as #960 (text parsed, numbers as days truncated toward zero), and NULL only beyond the range of int64 milliseconds. Times of day, timestamps and durations read the seconds that dbFetch() reads from a TIME or DATETIME column, in their unit. The time zone of a timestamp is only metadata and is not checked, so a string that names no zone, such as "Not/AZone", is kept as it is: a check would need a time zone database that a stream's worker threads can't take from R. the value is always the time since 1970-01-01 00:00:00 UTC, so text without an offset such as '2020-01-01 12:00:00' is read as UTC and text with an offset is shifted to UTC, as SQLite's datetime() and #885 do, also for a timestamp without a time zone, whose wall-clock time is then UTC's. A duration is the hms duration of dbFetch(): signed and beyond a day as written, or a time of day in UTC with an offset. Times of day keep the rules of #960 (24:00:00 and negative times are NULL, a real is checked against the day before rounding and stops at the last unit of the day), and a time or duration with an offset ends at 24:00:00 in full precision, as SQLite's time() does: '24:00:00.0000005+00:00' is NULL like '24:00:00.000001+00:00' (fixed after review in 4fafe90, red before).

Reals are rounded to the nearest unit of the value the double holds, halves to even, with the exact rounding of #960 generalized to every unit. Text keeps nine digits of the fraction for nanoseconds (the parsers stop at microseconds, so the further digits are read separately), and drops the digits that a coarser unit doesn't hold as written: a timestamp or time of day keeps the whole unit before them (so '1969-12-31 23:59:59.5' is -1 in seconds), a duration is truncated toward zero. Seconds and milliseconds count these values through #961's warnings as rounded (reals) or truncated (text), since dbFetch() keeps them; microseconds and nanoseconds count nothing, as #960 doesn't. Values beyond int64 in the unit are NULL as out of range, such as timestamps outside 1677 to 2262 in nanoseconds, including the smallest int64, which bit64 reads as NA. All of this is R-free and runs unchanged on a worker thread (#978), whose warnings go through its queue.

Tested in the new tests/testthat/test-arrow-requested-temporal.R: large types against utf8 and binary, beyond the byte limit in one chunk while utf8 fails; date64 at its range limits; each time unit with fractions, offsets, 24:00:00, negative and out-of-day values, reals at the end of the day; timestamps in each unit with no time zone, UTC, a named zone and an offset zone, text with and without offsets, before 1970, halves of reals; nanosecond and second range edges exactly; durations in each unit, signed and beyond a day; text forms with fields of one digit, offsets after a space and ten fraction digits; declared DATE, TIME and DATETIME columns overridden; later chunks with NULL-only first chunks and refused other units or zones; and a stream read on a worker thread through #978's hook with its queued warnings. The list of unsupported types in test-arrow-requested-types.R now holds types that stay unsupported. Full suite with NOT_CRAN=true: FAIL 0, WARN 3 (the zh_TW.UTF-8 locale is missing in the container), SKIP 64, PASS 14027. Valgrind on the new test file: 0 errors, 0 bytes definitely lost.

Item 14 of the plan in #829 (comment), a layer of the rebuilt chain planned in #880; based on #979 (item 13). Not ported from an old PR: the parsing and rounding rules are those of #960 and #885, extended to other units.

Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4



Generated by Claude Code

… unit and time zone

An Arrow fetch can now request large_utf8, large_binary, date64,
time32 in seconds or milliseconds, time64 in microseconds or nanoseconds,
and timestamp and duration in any unit, a timestamp with any time zone or none.
The requested types keep their unit and time zone, see ArrowColumnType.
Large columns have no byte limit of their own:
the rows that a fetch asks for bound their chunk.
The time zone of a timestamp is only metadata:
text without an offset is UTC, an offset shifts it to UTC.
Seconds and milliseconds round reals and drop digits of text,
and count these values as rounded or truncated;
nanoseconds keep nine digits of text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
@krlmlr
krlmlr added this pull request to stack #928 December 1, 2026 14:50
krlmlr and others added 3 commits December 1, 2026 14:57
parse_time() allows a time with an offset up to 24:00:00 in microseconds,
and the nanosecond digits came after that check,
so '24:00:00.0000005+00:00' read as 500 ns where SQLite's time() gives NULL.
The time zone of a requested timestamp stays unchecked, now said in a comment,
and the comments on rounded and truncated values name the temporal units.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4

krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Question: should requested large_utf8 and large_binary columns have a byte limit per chunk?

utf8 and binary arrays have 32-bit offsets, so #963 ends a chunk before such a column exceeds 2^31 - 1 bytes. Their large_ variants have 64-bit offsets, and this pull request exempts them from that limit, see fits(). A chunk of a requested large_ column is then bounded only by its row count (65536 rows for a stream), and running out of memory raises an error. Other columns of the same chunk keep the 2^31 - 1 limit.

  • No byte limit for large_ columns, as implemented: they exist for values beyond 2 GiB per chunk, and the row count bounds a chunk (recommended)
  • A configurable byte limit per chunk for large_ columns too, e.g. an internal option that item 18 could expose: predictable memory, one more knob
  • The same 2^31 - 1 limit as for utf8: simplest, but then large_ gains nothing over utf8 except the offset width

Kirill decides. Until then the first option stays as implemented.


Generated by Claude Code

krlmlr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Question: how should a requested timestamp with a named time zone read text without an offset?

This pull request builds requested timestamps in any unit, with or without a time zone. The stored value is always the UTC epoch, and a named zone such as Europe/Vienna only goes into the type's metadata. Text without an offset, such as '2020-07-01 12:00:00', is read as UTC whatever the zone, see the rule, so it shows as 14:00 in Vienna. That matches dbFetch() with extended_types = TRUE, which reads such text as UTC too. Text with an offset is shifted to UTC, as SQLite's datetime() does; for a timestamp without a zone that gives the UTC wall clock. Reading the text as local time in the named zone would need a time-zone database on the C++ side, which RSQLite doesn't have off R, and worker-thread reads (#978) can't call R.

  • Read text without an offset as UTC for every zone, as implemented: consistent with dbFetch(), works on worker threads (recommended)
  • Read it as local time in the named zone: matches what a user who requested the zone probably means, but needs a time-zone database in C++ (e.g. vendoring one) and is a sizeable addition
  • Refuse a named zone for columns that hold text without an offset (NULL with a warning): no silent shift, but most stored text has no offset

Kirill decides. Until then the first option stays as implemented.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants