| 333 | } |
| 334 | |
| 335 | Status Finish(std::shared_ptr<ChunkedArray>* out) override { |
| 336 | RETURN_NOT_OK(task_group_->Finish()); |
| 337 | |
| 338 | if (promotion_graph_ != nullptr) { |
| 339 | // insert absent child chunks |
| 340 | for (auto&& name_index : name_to_index_) { |
| 341 | auto child_builder = child_builders_[name_index.second].get(); |
| 342 | |
| 343 | RETURN_NOT_OK(child_builder->ReplaceTaskGroup(TaskGroup::MakeSerial())); |
| 344 | |
| 345 | for (size_t i = 0; i < chunk_lengths_.size(); ++i) { |
| 346 | if (child_absent_[i].size() > static_cast<size_t>(name_index.second) && |
| 347 | !child_absent_[i][name_index.second]) { |
| 348 | continue; |
| 349 | } |
| 350 | auto empty = std::make_shared<NullArray>(chunk_lengths_[i]); |
| 351 | child_builder->Insert(i, promotion_graph_->Null(name_index.first), empty); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | std::vector<std::shared_ptr<Field>> fields(name_to_index_.size()); |
| 357 | std::vector<std::shared_ptr<ChunkedArray>> child_arrays(name_to_index_.size()); |
| 358 | for (auto&& name_index : name_to_index_) { |
| 359 | auto child_builder = child_builders_[name_index.second].get(); |
| 360 | |
| 361 | std::shared_ptr<ChunkedArray> child_array; |
| 362 | RETURN_NOT_OK(child_builder->Finish(&child_array)); |
| 363 | |
| 364 | child_arrays[name_index.second] = child_array; |
| 365 | fields[name_index.second] = field(name_index.first, child_array->type()); |
| 366 | } |
| 367 | |
| 368 | auto type = struct_(std::move(fields)); |
| 369 | ArrayVector chunks(null_bitmap_chunks_.size()); |
| 370 | for (size_t i = 0; i < null_bitmap_chunks_.size(); ++i) { |
| 371 | ArrayVector child_chunks; |
| 372 | for (const auto& child_array : child_arrays) { |
| 373 | child_chunks.push_back(child_array->chunk(static_cast<int>(i))); |
| 374 | } |
| 375 | chunks[i] = std::make_shared<StructArray>(type, chunk_lengths_[i], child_chunks, |
| 376 | null_bitmap_chunks_[i]); |
| 377 | } |
| 378 | |
| 379 | *out = std::make_shared<ChunkedArray>(std::move(chunks), type); |
| 380 | return Status::OK(); |
| 381 | } |
| 382 | |
| 383 | Status ReplaceTaskGroup(const std::shared_ptr<TaskGroup>& task_group) override { |
| 384 | RETURN_NOT_OK(task_group_->Finish()); |