Skip to content

feat: support record batch custom metadata - #85

Merged
jheer merged 1 commit into
uwdata:mainfrom
Query-farm:upstream/batch-metadata
Nov 10, 2026
Merged

jheer merged 1 commit into
uwdata:mainfrom
Query-farm:upstream/batch-metadata

Conversation

@rustyconover

Copy link
Copy Markdown
Contributor

Implements the proposal in #84. Closes #84.

The Arrow IPC Message table carries an optional custom_metadata field. Flechette currently drops it on decode and never writes it (src/encode/message.js marked it NOT SUPPORTED). This PR adds it for record batch messages:

  • Decode: tableFromIPC sets table.batchMetadata to an array with one Map<string, string> (or null) per record batch. If no batch carries metadata it stays null, and decoded record batch objects are unchanged.
  • Encode: tableToIPC(table, { batchMetadata }) writes entry i on the i-th record batch message. The option defaults to table.batchMetadata, so a decode → encode round trip keeps the metadata, and a constructed table can set the property directly. Supplying more entries than the table has record batches throws, instead of silently dropping metadata.
  • select / selectAt carry batchMetadata over, because the selected columns share the same record batches.

On the open questions from #84: this covers record batches only. Dictionary batch metadata is not surfaced, since nothing in the Table model would hold it, and Arrow JS exposes only RecordBatch.metadata. The property lives on Table because Flechette tables have no record batch objects; batch i corresponds to column.data[i].

The change adds 137 lines, 81 of them tests. Reading reuses the existing decodeMetadata, and writing reuses the existing encodeMetadata, passed into writeMessage.

Validation:

  • 227 tests pass on Node 26; lint and the bundle/declaration builds pass.
  • The 11 new tests, all of which fail without the change, cover:
    • decoding Arrow JS–written metadata (stream and file)
    • encoding metadata that Arrow JS reads back as RecordBatch.metadata, including dictionary columns
    • default round trips, the option overriding the table property, null when absent, select, and the too-many-entries error
  • Checked by hand against pyarrow 24: a pyarrow stream with per-batch metadata and dictionary columns decodes correctly, and Flechette's re-encode reads back in pyarrow via read_next_batch_with_custom_metadata with the same metadata per batch.

I'm happy to change the property name or API shape if you'd prefer something else.

Decode and encode the Arrow IPC Message custom_metadata field for record batches. tableFromIPC exposes it as Table.batchMetadata, one Map (or null) per record batch, and tableToIPC writes it from a new batchMetadata option that defaults to the table property, so metadata survives a decode/encode round trip. Tables without batch metadata are unchanged.

Closes uwdata#84.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jheer
jheer merged commit 03a8028 into uwdata:main Nov 10, 2026
2 checks passed
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.

Proposal: support record batch custom_metadata (IPC Message field 4)

2 participants