Skip to content

Conversation

@rustyconover
Copy link

@rustyconover rustyconover commented Jan 7, 2026

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:

  • 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']]));

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']]));
@amoeba amoeba requested review from domoritz and trxcllnt January 14, 2026 17:12
Copy link
Contributor

@trxcllnt trxcllnt left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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>) {
Copy link
Contributor

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?

Suggested change
public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0, metadata?: Map<string, string>) {
public static from(header: Schema | RecordBatch | DictionaryBatch, bodyLength = 0) {

Copy link
Contributor

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.

Comment on lines +52 to +56
const batch = createTestBatch();
const metadata = new Map([['batch_id', '123'], ['source', 'test']]);

const writer = new RecordBatchStreamWriter();
writer.write(batch, metadata);
Copy link
Contributor

@trxcllnt trxcllnt Jan 15, 2026

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:

Suggested change
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);

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.

2 participants