-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Add custom metadata support for IPC messages and RecordBatch #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Decode and expose custom metadata from IPC message headers, propagating it through the reader to RecordBatch instances. This allows accessing per-batch metadata stored in Arrow IPC streams and files.
Extend RecordBatchWriter to support writing custom metadata to IPC
messages, similar to PyArrow's write_batch(batch, custom_metadata=...).
Changes:
- Update Message.from() to accept optional metadata parameter
- Update Message.encode() to serialize custom metadata to FlatBuffers
- Add customMetadata parameter to RecordBatchWriter.write()
- Add mergeMetadata() helper that combines batch.metadata with the
parameter (parameter takes precedence for duplicate keys)
- Add comprehensive integration tests for write/read round-trip
Usage:
writer.write(batch, new Map([['key', 'value']]));
trxcllnt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, just a few questions about the writer API.
| } | ||
| if (header instanceof RecordBatch) { | ||
| return new Message(bodyLength, MetadataVersion.V5, MessageHeader.RecordBatch, header); | ||
| return new Message(bodyLength, MetadataVersion.V5, MessageHeader.RecordBatch, header, metadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return new Message(bodyLength, MetadataVersion.V5, MessageHeader.RecordBatch, header, metadata); | |
| return new Message(bodyLength, MetadataVersion.V5, MessageHeader.RecordBatch, header, header.metadata); |
|
|
||
| /** @nocollapse */ | ||
| public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0) { | ||
| public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0, metadata?: Map<string, string>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the second metadata argument is only relevant if we're serializing a RecordBatch message, can we just use its metadata field instead?
| public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0, metadata?: Map<string, string>) { | |
| public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the Message reads the metadata from the RecordBatch, this can all be simplified.
| const batch = createTestBatch(); | ||
| const metadata = new Map([['batch_id', '123'], ['source', 'test']]); | ||
|
|
||
| const writer = new RecordBatchStreamWriter(); | ||
| writer.write(batch, metadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can do this:
| const batch = createTestBatch(); | |
| const metadata = new Map([['batch_id', '123'], ['source', 'test']]); | |
| const writer = new RecordBatchStreamWriter(); | |
| writer.write(batch, metadata); | |
| const batch = createTestBatch(); | |
| batch.metadata.set('batch_id', '123'); | |
| batch.metadata.set('source', 'test'); | |
| const writer = new RecordBatchStreamWriter(); | |
| writer.write(batch); |
What's Changed
Decode and expose custom metadata from IPC message headers, propagating it through the reader to RecordBatch instances. This allows accessing per-batch metadata stored in Arrow IPC streams and files.
Extend RecordBatchWriter to support writing custom metadata to IPC messages, similar to PyArrow's write_batch(batch, custom_metadata=...).
Changes:
parameter (parameter takes precedence for duplicate keys)
Usage:
writer.write(batch, new Map([['key', 'value']]));