← Back to Pull requests

feat: add `custom_metadata` support to `RecordBatch` with IPC read/write #9445

Open
unknown opened this pull request with 325 lines diff across 4 files
View on GitHub
unknown unknown commented on Feb 20, 2026 02:57 UTC
Author

Which issue does this PR close?

  • Closes #9444.
  • Rationale for this change

    The IPC Message flatbuffer envelope has a custom_metadata field for per-batch key-value metadata, separate from schema-level metadata. arrow-rs currently drops it on read and has no way to write it. PyArrow supports it (write_batch(custom_metadata=...), since v11.0.0), as do arrow-go and arrow-js.

    What changes are included in this PR?

    Add per-batch custom_metadata to RecordBatch, stored as arrow_schema::Metadata (introduced in #10075). An empty Metadata does not allocate, so RecordBatch grows by a single pointer (40 → 48 bytes). Clones share the underlying map, and IPC encoding is deterministic (sorted by key).

  • New RecordBatch methods:

  •   fn custom_metadata(&self) -> &Metadata;
      fn custom_metadata_mut(&mut self) -> &mut Metadata;  // copy-on-write if shared
      fn with_custom_metadata(self, metadata: impl Into<Metadata>) -> Self;
      fn into_parts_with_custom_metadata(self) -> (SchemaRef, Vec<ArrayRef>, usize, Metadata);
      

  • IPC writer: serializes custom_metadata to the Message flatbuffer via convert::metadata_to_fb

  • IPC reader: new reader::message_custom_metadata; FileDecoder, StreamReader, and StreamDecoder attach the metadata to decoded batches

  • arrow-flight: flight_data_to_arrow_batch extracts and attaches custom_metadata

  • arrow-select: filter_record_batch and take_record_batch preserve custom_metadata

  • Metadata is preserved through slice(), project(), normalize(), with_schema(), and remove_column()
  • Are these changes tested?

    Yes:

  • Unit tests for the RecordBatch API (setting, mutating, copy-on-write, sharing between batches, equality, and preservation through slice/project)

  • IPC file, stream, and StreamDecoder round-trips, including multiple batches with different metadata and batches without metadata

  • PyArrow-generated test files (arrow-ipc/test_data/custom_metadata.arrow_{file,stream}) for cross-language interop

  • Tests that filter_record_batch and take_record_batch preserve the metadata
  • Are there any user-facing changes?

    Yes, new public APIs on RecordBatch and arrow_ipc::reader::message_custom_metadata. There are no breaking changes: existing constructors produce batches with empty metadata, and PartialEq now also compares custom_metadata.

    Written with AI assistance; all changes reviewed by the author.

    🤖 Generated with Claude Code

    Diff: 325 lines (+243 / -82) across 4 files Reviewer: rustyconover Review duration: 408301m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.49) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 325 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.346
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9445"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49% (MEDIUM) · Higher = larger blast radius
    49%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.9% · Safe to merge
    28.9%