Repository navigation
arrow-ipc: add reset method to DictionaryTracker - #9196
Conversation
| assert_eq!(read_batch, batch1); | ||
|
|
||
| // reset the dictionary tracker so it can be used for next stream | ||
| dictionary_tracker.reset(); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Thanks for this contribution @albertlockett -- I had some small API suggestions. Let me know what you think
| /// 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) { |
There was a problem hiding this comment.
Some thoughts:
- Perhaps we can call this method
clearso that it mirrors the clear methods on Vec, HashMap, etc? - Should we also reset
error_on_replacementfield?. It seems like maybe it is ok not to I just wanted to checkarrow-rs/arrow-ipc/src/writer.rs
Lines 832 to 834 in 91b1405
- Perhaps we could leave a comment in
DictionaryTrackerfields that reminds anyone who adds a field they have to also update reset?
There was a problem hiding this comment.
@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).
Co-authored-by: Andrew Lamb <[email protected]>
| 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(); |
…(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 -->
…(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 -->
Which issue does this PR close?
DictionaryTrackerwhen creating new IPC Stream #9195 .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.
DictionaryTrackeris 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
resetto theDictionaryTrackerso 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