`split_batch_for_grpc_response` over-splits batches after IPC deserialization
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 169
Description
**Describe the bug**
`split_batch_for_grpc_response` uses [this](https://github.com/apache/arrow-rs/blob/54d81919206d667d36ba4b5f76ff8e7ed9d341dd/arrow-flight/src/encode.rs#L621) to estimate batch size for splitting. This calls buffer.capacity(), which reports the full backing allocation size, not the actual data size.
After IPC deserialization, the IPC reader creates all buffers by slicing one shared `Buffer` via [this](https://github.com/apache/arrow-rs/blob/54d81919206d667d36ba4b5f76ff8e7ed9d341dd/arrow-buffer/src/buffer/immutable.rs#L298-L312), which clones the Arc. So every buffer's capacity() reports the entire message body size rather than its own slice.
**To Reproduce**
`FlightDataEncoderBuilder` encode -> `FlightRecordBatchStream` decode -> `FlightDataEncoderBuilder` re-encode produces more FlightData than just `FlightDataEncoderBuilder` encode
**Expected behavior**
**Additional context**
#5352
Contributor guide
Assessment
This issue has not been assessed yet.