Split [`RecordBatch`] so it hopefully fits into a gRPC response. Data is zero-copy sliced into batches. Note: this method does not take into account already sliced arrays:
(
batch: RecordBatch,
max_flight_data_size: usize,
)
| 669 | /// Note: this method does not take into account already sliced |
| 670 | /// arrays: <https://github.com/apache/arrow-rs/issues/3407> |
| 671 | fn split_batch_for_grpc_response( |
| 672 | batch: RecordBatch, |
| 673 | max_flight_data_size: usize, |
| 674 | ) -> Vec<RecordBatch> { |
| 675 | let size = batch |
| 676 | .columns() |
| 677 | .iter() |
| 678 | .map(|col| col.get_buffer_memory_size()) |
| 679 | .sum::<usize>(); |
| 680 | |
| 681 | let n_batches = |
| 682 | (size / max_flight_data_size + usize::from(size % max_flight_data_size != 0)).max(1); |
| 683 | let rows_per_batch = (batch.num_rows() / n_batches).max(1); |
| 684 | let mut out = Vec::with_capacity(n_batches + 1); |
| 685 | |
| 686 | let mut offset = 0; |
| 687 | while offset < batch.num_rows() { |
| 688 | let length = (rows_per_batch).min(batch.num_rows() - offset); |
| 689 | out.push(batch.slice(offset, length)); |
| 690 | |
| 691 | offset += length; |
| 692 | } |
| 693 | |
| 694 | out |
| 695 | } |
| 696 | |
| 697 | /// The data needed to encode a stream of flight data, holding on to |
| 698 | /// shared Dictionaries. |