Skip to content

[Rust] Expose Arrow batch encoded byte sizes - #790

Open
flaviofcruz wants to merge 1 commit into
mainfrom
rust-arrow-batch-byte-size
Open

[Rust] Expose Arrow batch encoded byte sizes#790
flaviofcruz wants to merge 1 commit into
mainfrom
rust-arrow-batch-byte-size

Conversation

@flaviofcruz

Copy link
Copy Markdown
Collaborator

What changes are proposed in this pull request?

Add ZerobusArrowStream::take_offset_details, returning Some(OffsetDetails) with the encoded wire byte size of the batch at an offset and the cumulative wire bytes sent through it. Callers report an accurate bytes-sent metric without re-serialising the RecordBatch (issue #779); None when no size is recorded.

To make this happen, we carry the OffsetId alongside the RecordBatch so that we can encode the size. The stats recorder keeps only a certain amount of stats so if they are not consumed, the user won't be able to recover them, so they have to be consumed after waiting for the offset.

This change will be used to track the vector's databricks_zerobus bytes sent which is helpful to debug what is happening.

An alternative design that was considered was to introduce a separate wait_for_offset called wait_for_offset_with_details which waits for the offset and then immediately returns the stats. The downside is that we end up with multiple similar functions but can do that if you feel that's better.

How is this tested?

Added several unit tests.

@flaviofcruz
flaviofcruz force-pushed the rust-arrow-batch-byte-size branch from ac4226c to 271bdab Compare August 28, 2026 15:55
Add ZerobusArrowStream::take_offset_details, returning Some(OffsetDetails)
for the batch at an offset, or None when no size is recorded. OffsetDetails
reports both wire_byte_size (actual on-wire bytes, after IPC compression —
maps to Vector SinkNetworkBytesSent) and uncompressed_byte_size (encoded size
before compression, codec-independent — maps to ComponentBytesSent), each with
a monotonic running total. Lets callers report bytes-sent metrics without
re-serialising the RecordBatch (issue #779).

The batch channel carries each batch's OffsetId alongside the RecordBatch, so
the Flight encoder keys sizes by the durable OffsetId. Wire bytes come from the
emitted FlightData frame; the uncompressed size is a cheap per-batch Arrow
buffer-byte sum (no re-encode), so it stays independent of the wire codec. All
sizes accumulate across retransmits. State lives in a bounded BatchStatsTracker;
reads are consume-once.

Additive: wait_for_offset/flush and the FFI/JNI/PyO3 surfaces are unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Flavio Cruz <flavio.cruz@databricks.com>
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.

1 participant