MCPcopy Create free account
hub / github.com/apache/arrow-rs / split_batch_for_grpc_response

Function split_batch_for_grpc_response

arrow-flight/src/encode.rs:671–695  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

669/// Note: this method does not take into account already sliced
670/// arrays: <https://github.com/apache/arrow-rs/issues/3407>
671fn 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.

Callers 3

encode_batchMethod · 0.85
verify_splitFunction · 0.85

Calls 7

maxMethod · 0.80
iterMethod · 0.45
columnsMethod · 0.45
num_rowsMethod · 0.45
pushMethod · 0.45
sliceMethod · 0.45

Tested by 1