| 532 | std::string ExecNode::ToStringExtra(int indent) const { return ""; } |
| 533 | |
| 534 | std::shared_ptr<RecordBatchReader> MakeGeneratorReader( |
| 535 | std::shared_ptr<Schema> schema, std::function<Future<std::optional<ExecBatch>>()> gen, |
| 536 | MemoryPool* pool) { |
| 537 | struct Impl : RecordBatchReader { |
| 538 | std::shared_ptr<Schema> schema() const override { return schema_; } |
| 539 | |
| 540 | Status ReadNext(std::shared_ptr<RecordBatch>* record_batch) override { |
| 541 | ARROW_ASSIGN_OR_RAISE(auto batch, iterator_.Next()); |
| 542 | if (batch) { |
| 543 | ARROW_ASSIGN_OR_RAISE(*record_batch, batch->ToRecordBatch(schema_, pool_)); |
| 544 | } else { |
| 545 | *record_batch = IterationEnd<std::shared_ptr<RecordBatch>>(); |
| 546 | } |
| 547 | return Status::OK(); |
| 548 | } |
| 549 | |
| 550 | Status Close() override { |
| 551 | // reading from generator until end is reached. |
| 552 | std::shared_ptr<RecordBatch> batch; |
| 553 | RETURN_NOT_OK(ReadNext(&batch)); |
| 554 | while (batch != nullptr) { |
| 555 | RETURN_NOT_OK(ReadNext(&batch)); |
| 556 | } |
| 557 | return Status::OK(); |
| 558 | } |
| 559 | |
| 560 | MemoryPool* pool_; |
| 561 | std::shared_ptr<Schema> schema_; |
| 562 | Iterator<std::optional<ExecBatch>> iterator_; |
| 563 | }; |
| 564 | |
| 565 | auto out = std::make_shared<Impl>(); |
| 566 | out->pool_ = pool; |
| 567 | out->schema_ = std::move(schema); |
| 568 | out->iterator_ = MakeGeneratorIterator(std::move(gen)); |
| 569 | return out; |
| 570 | } |
| 571 | |
| 572 | Result<ExecNode*> Declaration::AddToPlan(ExecPlan* plan, |
| 573 | ExecFactoryRegistry* registry) const { |