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

Class RowGroupGenerator

cpp/src/parquet/arrow/reader.cc:1147–1260  ·  view source on GitHub ↗

Given a file reader and a list of row groups, this is a generator of record batch generators (where each sub-generator is the contents of a single row group).

Source from the content-addressed store, hash-verified

1145/// Given a file reader and a list of row groups, this is a generator of record
1146/// batch generators (where each sub-generator is the contents of a single row group).
1147class RowGroupGenerator {
1148 public:
1149 using RecordBatchGenerator =
1150 ::arrow::AsyncGenerator<std::shared_ptr<::arrow::RecordBatch>>;
1151
1152 struct ReadRequest {
1153 ::arrow::Future<RecordBatchGenerator> read;
1154 int64_t num_rows;
1155 };
1156
1157 explicit RowGroupGenerator(std::shared_ptr<FileReaderImpl> arrow_reader,
1158 ::arrow::internal::Executor* cpu_executor,
1159 std::vector<int> row_groups, std::vector<int> column_indices,
1160 int64_t min_rows_in_flight)
1161 : arrow_reader_(std::move(arrow_reader)),
1162 cpu_executor_(cpu_executor),
1163 row_groups_(std::move(row_groups)),
1164 column_indices_(std::move(column_indices)),
1165 min_rows_in_flight_(min_rows_in_flight),
1166 rows_in_flight_(0),
1167 index_(0),
1168 readahead_index_(0) {}
1169
1170 ::arrow::Future<RecordBatchGenerator> operator()() {
1171 if (index_ >= row_groups_.size()) {
1172 return ::arrow::AsyncGeneratorEnd<RecordBatchGenerator>();
1173 }
1174 index_++;
1175 FillReadahead();
1176 ReadRequest next = std::move(in_flight_reads_.front());
1177 DCHECK(!in_flight_reads_.empty());
1178 in_flight_reads_.pop();
1179 rows_in_flight_ -= next.num_rows;
1180 return next.read;
1181 }
1182
1183 private:
1184 void FillReadahead() {
1185 if (min_rows_in_flight_ == 0) {
1186 // No readahead, fetch the batch when it is asked for
1187 FetchNext();
1188 } else {
1189 while (readahead_index_ < row_groups_.size() &&
1190 rows_in_flight_ < min_rows_in_flight_) {
1191 FetchNext();
1192 }
1193 }
1194 }
1195
1196 void FetchNext() {
1197 size_t row_group_index = readahead_index_++;
1198 int row_group = row_groups_[row_group_index];
1199 std::vector<int> column_indices = column_indices_;
1200 auto reader = arrow_reader_;
1201 int64_t num_rows =
1202 reader->parquet_reader()->metadata()->RowGroup(row_group)->num_rows();
1203 rows_in_flight_ += num_rows;
1204 ::arrow::Future<RecordBatchGenerator> row_group_read;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected