Skip to content

feat: Add DictionaryBatch write support to IPC encoder and writer - #926

Merged
paleolimbot merged 3 commits into
apache:mainfrom
niekverw:feat/dictionary-batch-encoding
Sep 8, 2026
Merged

paleolimbot merged 3 commits into
apache:mainfrom
niekverw:feat/dictionary-batch-encoding

Conversation

@niekverw

Copy link
Copy Markdown
Contributor

Hi, I had implemented dictionary batch writing for a project that I was working on, I noticed a thread (#622) about it, so I just wanted to share what I had in case it is useful. I needed this for a project that emits dictionary-encoded columns over IPC. I use ArrowIpcWriterWriteDictionaryBatch directly, for the PR I wired it into WriteArrayStream so dictionaries get emitted automatically on the high-level path and added a write→read round-trip test. Happy to also adjust.

@niekverw
niekverw marked this pull request as draft August 25, 2026 02:14
@niekverw
niekverw force-pushed the feat/dictionary-batch-encoding branch from c2c74ae to 8dfc378 Compare August 25, 2026 02:14
@niekverw
niekverw marked this pull request as ready for review August 25, 2026 02:15
@rustyconover

Copy link
Copy Markdown
Contributor

Hi @niekverw I took where you started and iterated on it a bit. Thanks for the taking the first crack at this dictionary write support.

@paleolimbot

Copy link
Copy Markdown
Member

Sorry that I didn't notice this PR! I was on vacation when you added it and my notifications only caught Rusty's PR.

If you're still keen to pursue this I'm back from vacation now and happy to review. Rusty's also taken on delta dictionary support which I think is mostly independent of this.

@codecov-commenter

codecov-commenter commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.29%. Comparing base (f11d517) to head (840757e).
⚠️ Report is 85 commits behind head on main.

Files with missing lines Patch % Lines
src/nanoarrow/ipc/encoder.c 37.25% 9 Missing and 23 partials ⚠️
src/nanoarrow/ipc/writer.c 69.69% 0 Missing and 10 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #926      +/-   ##
==========================================
- Coverage   79.96%   79.29%   -0.68%     
==========================================
  Files         105      106       +1     
  Lines       15461    16316     +855     
  Branches     1738     1925     +187     
==========================================
+ Hits        12364    12937     +573     
- Misses       1998     2163     +165     
- Partials     1099     1216     +117     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great work!

The CI failure is a small test issue...other than that just a question to make sure I'm understanding the nested dictionary situation.

@rustyconover I think we can merge this after fixing the test leak an integrate your additional work on top. What do you think?

Comment thread src/nanoarrow/ipc/writer_test.cc
Comment on lines +362 to +364
// Emitting a full (non-delta) DictionaryBatch for each dictionary before every
// RecordBatch keeps each batch's indices valid against the dictionary that precedes
// it, which is required because each array in the stream carries its own dictionary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a good scope for this PR, but we will want to ensure we have some way to avoid emitting duplicate dictionaries as tracked follow-up.

Comment on lines +379 to +382
if (array_view->dictionary != NULL) {
NANOARROW_RETURN_NOT_OK(ArrowIpcWriterWriteDictionariesForArrayView(
writer, array_view->dictionary, next_id, error));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The encoder rejects dictionary values that have a dictionary. Should this error instead? (Or if it works, can we add a test?)

@paleolimbot

Copy link
Copy Markdown
Member

I think before we merge this we should also more clearly make sure three things that aren't quite supported error effectively:

  • Nested dictionaries
  • Dictionaries values that contain children (e.g., where the dictionary value is a list or struct)
  • File footers, which don't populate dictionaries and aren't theoretically allowed to have more than one non delta dictionary per id.

@rustyconover

Copy link
Copy Markdown
Contributor

I think so too. I thought this PR was a great start thats why I did a bunch of work on top of it!

I'd like to get dictionary write support landed, because then I'll roll it out across a few of my Query Farm's projects and really start to use nanoarrow a lot more!

@niekverw

niekverw commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey all, no problem, just go with Rusty’s PR - I just wanted to share this as I was using it and seemed to work for me - no need to merge this specific PR if rusty has built a better solution.
thank you!!

@rustyconover

Copy link
Copy Markdown
Contributor

Thanks @niekverw

@paleolimbot

Copy link
Copy Markdown
Member

I'll push a small commit when I'm back at the keyboard Tuesday to get CI passing and catalog the required follow-up work, and we'll use Rusty's PR to clean up. This is great work and there's no reason your name shouldn't be on the commit!

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@paleolimbot paleolimbot changed the title feat(ipc): Add DictionaryBatch write support to IPC encoder and writer feat: Add DictionaryBatch write support to IPC encoder and writer Sep 8, 2026
@paleolimbot
paleolimbot merged commit 9dd6c4b into apache:main Sep 8, 2026
42 of 43 checks passed
pdet added a commit to pdet/arrow-nanoarrow that referenced this pull request Sep 9, 2026
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.

4 participants