MCPcopy Create free account
hub / github.com/apache/arrow / MakeChunkedBatchGenerator

Function MakeChunkedBatchGenerator

cpp/src/arrow/dataset/dataset_internal.h:140–157  ·  view source on GitHub ↗

Given a record batch generator, creates a new generator that slices batches so individual batches have at most batch_size rows. The resulting generator is async-reentrant, but does not forward reentrant pulls, so apply readahead before using this helper.

Source from the content-addressed store, hash-verified

138// resulting generator is async-reentrant, but does not forward
139// reentrant pulls, so apply readahead before using this helper.
140inline RecordBatchGenerator MakeChunkedBatchGenerator(RecordBatchGenerator gen,
141 int64_t batch_size) {
142 return MakeFlatMappedGenerator(
143 std::move(gen),
144 [batch_size](const std::shared_ptr<RecordBatch>& batch)
145 -> ::arrow::AsyncGenerator<std::shared_ptr<::arrow::RecordBatch>> {
146 const int64_t rows = batch->num_rows();
147 if (rows <= batch_size) {
148 return ::arrow::MakeVectorGenerator<std::shared_ptr<RecordBatch>>({batch});
149 }
150 std::vector<std::shared_ptr<RecordBatch>> slices;
151 slices.reserve(rows / batch_size + (rows % batch_size != 0));
152 for (int64_t i = 0; i < rows; i += batch_size) {
153 slices.push_back(batch->Slice(i, batch_size));
154 }
155 return ::arrow::MakeVectorGenerator(std::move(slices));
156 });
157}
158
159} // namespace dataset
160} // namespace arrow

Callers 3

GeneratorFromReaderFunction · 0.85
ScanBatchesAsyncMethod · 0.85
ScanBatchesAsyncMethod · 0.85

Calls 6

MakeFlatMappedGeneratorFunction · 0.85
MakeVectorGeneratorFunction · 0.85
push_backMethod · 0.80
num_rowsMethod · 0.45
reserveMethod · 0.45
SliceMethod · 0.45

Tested by

no test coverage detected