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.
| 138 | // resulting generator is async-reentrant, but does not forward |
| 139 | // reentrant pulls, so apply readahead before using this helper. |
| 140 | inline 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 |
no test coverage detected