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

Function MakeGeneratorReader

cpp/src/arrow/acero/exec_plan.cc:534–570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532std::string ExecNode::ToStringExtra(int indent) const { return ""; }
533
534std::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
572Result<ExecNode*> Declaration::AddToPlan(ExecPlan* plan,
573 ExecFactoryRegistry* registry) const {

Callers 3

TESTFunction · 0.85

Calls 1

MakeGeneratorIteratorFunction · 0.85

Tested by 1

TESTFunction · 0.68