Skip to content

Consider sink-based Arrow IPC StreamEncoder API #10445

Description

@Phoenix500526

Is your feature request related to a problem or challenge?

StreamEncoder::encode currently returns Vec<Buffer>. This keeps the API simple and sans-IO friendly, but it requires the encoder to collect all output buffers for a batch before the caller can forward them to its destination.

Describe the solution you'd like

An alternative API could push encoded pieces directly into a sink-like abstraction, for example:

pub fn encode_to<S: IpcMessageSink>(
    &mut self,
    batch: &RecordBatch,
    sink: &mut S,
) -> Result<(), ArrowError>

Describe alternatives you've considered

or make StreamEncoder generic over a sink.

This could reduce intermediate buffering and copying for callers that can consume IPC pieces immediately, such as async writers. The tradeoff is that the encoder starts to look more like a writer, and exposing a sink abstraction may make the public API more complex.

Things to evaluate:

  • Whether this should be additive, such as encode_to, instead of replacing encode
  • Whether the sink abstraction should be public
  • Whether this preserves the intended sans-IO API boundary
  • How it affects copy behavior and memory usage
  • Benchmark impact compared with encode -> Vec<Buffer>

Additional context

Follow-up from #10277 and review discussion:
#10277 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelog

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions