Repository navigation
feat(ipc): Add ArrowIpcWriterSetMessageMetadata - #967
Open
rustyconover wants to merge 1 commit into
Open
rustyconover wants to merge 1 commit into
rustyconover wants to merge 1 commit into
Conversation
Message::custom_metadata can be attached through the encoder (ArrowIpcEncoderSetMessageMetadata), but an ArrowIpcWriter's encoder is private, so a writer could not attach metadata to the RecordBatch messages it writes. The new function holds the metadata in the writer and attaches it to the next RecordBatch, not to DictionaryBatch messages written ahead of it (by ArrowIpcWriterWriteDictionaryBatch() or within ArrowIpcWriterWriteArrayStream()). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #967 +/- ##
==========================================
+ Coverage 78.24% 78.25% +0.01%
==========================================
Files 106 106
Lines 16901 16915 +14
Branches 2012 2015 +3
==========================================
+ Hits 13224 13237 +13
Misses 2435 2435
- Partials 1242 1243 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ArrowIpcEncoderSetMessageMetadata()(#924, narrowed in #937) attachesMessage::custom_metadatato the next message an encoder encodes. AnArrowIpcWriterkeeps its encoder private, though, so a caller using the writer has no way to attach metadata to the RecordBatch messages it writes. The only option is to drop down to the encoder and redo the writer's framing, footer bookkeeping and dictionary handling by hand.This PR adds
ArrowIpcWriterSetMessageMetadata(writer, metadata, error). The writer holds the metadata and attaches it to the next RecordBatch message written byArrowIpcWriterWriteArrayView()orArrowIpcWriterWriteArrayStream(). The metadata applies to that one message. PassingNULLclears metadata that has been set but not yet written. Like the encoder function, it takes ownership of the buffer.The metadata is held by the writer rather than set on the encoder right away. Setting it on the encoder would attach it to whichever message is encoded next, and that can be a DictionaryBatch written ahead of the batch. This happens both with an explicit
ArrowIpcWriterWriteDictionaryBatch()call and insideArrowIpcWriterWriteArrayStream(). RecordBatch-level metadata belongs on the RecordBatch, so the writer passes it to the encoder just before encoding that batch.Things worth a look in review:
WriteArrayStream()the metadata lands on the first RecordBatch only. Per-batch metadata over a stream would need a callback or a per-array side channel, which seemed out of scope. The batch-at-a-time pattern isSetMessageMetadata()+WriteArrayView().writer.c, so whichever lands second will need a small rebase. I can do that.Motivation: I'm moving the IPC layer of a DuckDB extension from Arrow C++ to nanoarrow. Its RPC protocol carries per-batch state in RecordBatch
custom_metadata(what Arrow C++ writes forRecordBatchWriter::WriteRecordBatch(batch, custom_metadata)), and this was the one thing the writer couldn't express.Tests:
MessageMetadataAttachesToNextRecordBatchsets metadata, writes a DictionaryBatch and then a RecordBatch, and checks that only the RecordBatch carries it. It also checks that the following batch doesn't inherit the metadata, and that set-then-cleared metadata is never written.MessageMetadataWithArrayStreamcoversWriteArrayStream()writing its own dictionaries.ctest passes locally (macOS arm64, Debug, ZSTD/LZ4, 390 tests). The IPC writer, encoder and files tests are clean under ASan/UBSan.
🤖 Generated with Claude Code