Skip to content

arrow-ipc: add reset method to DictionaryTracker - #9196

Merged
alamb merged 3 commits into
apache:mainfrom
albertlockett:albert/9195
Jan 17, 2026
Merged

alamb merged 3 commits into
apache:mainfrom
albertlockett:albert/9195

Conversation

@albertlockett

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When creating a new IPC stream, efficiency can be gained by reusing some of the types involved in building the stream to avoid some allocation cost. DictionaryTracker is a type that's difficult to reuse because there's no way to reset the internal state.

The linked issue has more discussion of my actual use case.

What changes are included in this PR?

Adds a method called reset to the DictionaryTracker so it can be reused when creating a new IPC stream, avoiding the allocation cost of creating a new instance.

Are these changes tested?

Yes I added a test. The test would fail unless this new method is called.

Are there any user-facing changes?

New public method on DictionaryTracker

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jan 15, 2026
Comment thread arrow-ipc/src/writer.rs Outdated
assert_eq!(read_batch, batch1);

// reset the dictionary tracker so it can be used for next stream
dictionary_tracker.reset();

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.

If this method weren't invoked, the test would fail with:

thread 'writer::tests::test_dictionary_tracker_reset' (19464958) panicked at arrow-ipc/src/writer.rs:4255:49:
called `Result::unwrap()` on an `Err` value: ParseError("Cannot find a dictionary batch with dict id: 1")

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this contribution @albertlockett -- I had some small API suggestions. Let me know what you think

Comment thread arrow-ipc/src/writer.rs Outdated
/// This allows the dictionary tracker to be reused for a new IPC stream while avoiding the
/// allocation cost of creating a new instance. This method should not be called if
/// the dictionary tracker will be used to continue writing to the an existing IPC stream.
pub fn reset(&mut self) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some thoughts:

  1. Perhaps we can call this method clear so that it mirrors the clear methods on Vec, HashMap, etc?
  2. Should we also reset error_on_replacement field?
    written: HashMap<i64, ArrayData>,
    dict_ids: Vec<i64>,
    error_on_replacement: bool,
    . It seems like maybe it is ok not to I just wanted to check
  3. Perhaps we could leave a comment in DictionaryTracker fields that reminds anyone who adds a field they have to also update reset?

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.

@alamb thanks for the review. Renamed to clear and added the comment reminding that future fields might need to be cleared.

WRT to error_on_replacement, I don't think the clear method should toggle this flag. This field is less like computed state, and more like a property that ensures the DictionaryTracker behaves correctly within the context in which it's used. As far as I know, the nominal use case for this flag is that it should be set to false when writing IPC file format (where dictionary replacement messages are not allowed).

Comment thread arrow-ipc/src/writer.rs Resolved

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @albertlockett

Comment thread arrow-ipc/src/writer.rs
let mut dictionary_tracker = DictionaryTracker::new(true);

// dictionaries are already written, so we can reset dictionary tracker to reuse for schema
self.dictionary_tracker.clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@alamb
alamb merged commit e565074 into apache:main Jan 17, 2026
github-merge-queue Bot pushed a commit to open-telemetry/otel-arrow that referenced this pull request Mar 27, 2026
…(0.13.2) (#2445)

# Change Summary

<!--
Replace with a brief summary of the change in this PR
-->

- Upgrades dependency versions Arrow (58.1) Datafusion (53.0.0) & Object
Store (0.13.2)
- Fix producer to reuse/reset the dictionary tracker instead of creating
a new one on stream resets apache/arrow-rs#9196

## What issue does this PR close?

<!--
We highly recommend correlation of every PR to an issue
-->

* Closes #2446

## How are these changes tested?

Existing unit tests

## Are there any user-facing changes?

No

 <!-- If yes, provide further info below -->
github-merge-queue Bot pushed a commit to open-telemetry/otel-arrow that referenced this pull request Mar 27, 2026
…(0.13.2) (#2445)

# Change Summary

<!--
Replace with a brief summary of the change in this PR
-->

- Upgrades dependency versions Arrow (58.1) Datafusion (53.0.0) & Object
Store (0.13.2)
- Fix producer to reuse/reset the dictionary tracker instead of creating
a new one on stream resets apache/arrow-rs#9196

## What issue does this PR close?

<!--
We highly recommend correlation of every PR to an issue
-->

* Closes #2446

## How are these changes tested?

Existing unit tests

## Are there any user-facing changes?

No

 <!-- If yes, provide further info below -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to reuse DictionaryTracker when creating new IPC Stream

2 participants