Skip to content

Pack Arrow Duration dictionary values via Int64 reinterpretation - #12349

Open
lwwmanning wants to merge 2 commits into
developfrom
wm/pack-arrow-duration-dicts
Open

lwwmanning wants to merge 2 commits into
developfrom
wm/pack-arrow-duration-dicts

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

arrow_cast does not support packing Duration arrays directly into Dictionary(K, Duration(_)), so any Duration input that reaches decode_to_dictionary (such as a plain Duration array exported to a dictionary field or joined dictionaries overflowing key width) fails on develop, and sparse Duration dictionary slices cannot repack. Since Arrow Duration shares Int64's physical layout, decode_to_dictionary now casts Duration to Int64, packs into Dictionary(K, Int64), and casts the deduplicated dictionary values back to Duration.

Assisted by Antigravity and Devin.

arrow_cast's dictionary packing omits Arrow Duration types, preventing
sparse Duration dictionary slices from repacking into Arrow
dictionaries. Reinterpret Duration values as Int64, pack via
arrow_cast, and reinterpret the resulting dictionary values back to
Duration without copying.

Co-Authored-By: Antigravity <noreply@google.com>
Signed-off-by: Will Manning <will@willmanning.io>
@lwwmanning lwwmanning added the changelog/fix A bug fix label Nov 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T00:21:37.421939Z 3ff5d91 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

The fix is correct, and the split from #12337 is clean. Two points.

From reading the code, on develop this does more than bloat sparse slices. decode_to_dictionary calls arrow_cast::cast to Dictionary(K, Duration), which arrow-cast does not support, so every Duration input that reaches it fails. For example, a canonical Duration extension array exported with a Dictionary(Int32, Duration(Millisecond)) field takes that path and errors. Could the description lead with that? Could the test also add one case for it, such as a plain Duration array, or two Duration dictionaries whose joined values overflow Int8 keys?

The two unit matches can go. The arrow-cast crate packs Timestamp and the time types this way in pack_array_to_dictionary_via_primitive. It also supports Duration to Int64 (a reinterpret) and Int64 to Duration. So cast(&array, Int64), then cast(.., Dictionary(K, Int64)), then cast(.., Dictionary(K, Duration(unit))) does the same thing in about 8 lines. It needs no ArrowTimeUnit import and no manual DictionaryArray::try_new. The last cast touches only the deduplicated values.

@devin-ai-integration devin-ai-integration Bot added the quick-review Small, self-contained change that is quick to review label Nov 30, 2026
…ration export

Replace the per-TimeUnit reinterpret matches and manual DictionaryArray
construction with arrow_cast casts through Int64 and Dictionary(K, Int64),
and add a regression test for exporting a plain Duration array to an Arrow
dictionary field.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed both points in a2d70d1: replaced the per-TimeUnit matches and manual DictionaryArray::try_new with arrow_cast::cast through Int64 / Dictionary(K, Int64), added a test exporting a plain nullable Duration array to a dictionary field, and updated the PR description to lead with the decode_to_dictionary failure on develop.

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

changelog/fix A bug fix quick-review Small, self-contained change that is quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant