Convert a `Declaration` using `QueryOptions` to a `RecordBatch` generator. Additional outputs: `out_schema` is the schema for the generated record batches `out_plan` is the backing `ExecPlan`, which may be stopped to cancel the generation
| 1005 | // * `out_schema` is the schema for the generated record batches |
| 1006 | // * `out_plan` is the backing `ExecPlan`, which may be stopped to cancel the generation |
| 1007 | Result<AsyncGenerator<std::shared_ptr<RecordBatch>>> DeclarationToRecordBatchGenerator( |
| 1008 | Declaration declaration, QueryOptions options, |
| 1009 | ::arrow::internal::Executor* cpu_executor, std::shared_ptr<Schema>* out_schema, |
| 1010 | std::shared_ptr<ExecPlan>* out_plan) { |
| 1011 | if (out_plan == nullptr) { |
| 1012 | std::shared_ptr<ExecPlan> tmp_plan; |
| 1013 | return DeclarationToRecordBatchGenerator(std::move(declaration), std::move(options), |
| 1014 | cpu_executor, out_schema, &tmp_plan); |
| 1015 | } |
| 1016 | auto converter = std::make_shared<BatchConverter>(); |
| 1017 | ExecContext exec_ctx(options.memory_pool, cpu_executor, options.function_registry); |
| 1018 | std::shared_ptr<ExecPlan>& plan = *out_plan; |
| 1019 | ARROW_ASSIGN_OR_RAISE(plan, ExecPlan::Make(options, exec_ctx)); |
| 1020 | Declaration with_sink = Declaration::Sequence( |
| 1021 | {declaration, |
| 1022 | {"sink", SinkNodeOptions(&converter->exec_batch_gen, &converter->schema)}}); |
| 1023 | ARROW_RETURN_NOT_OK(with_sink.AddToPlan(plan.get())); |
| 1024 | ARROW_RETURN_NOT_OK(plan->Validate()); |
| 1025 | plan->StartProducing(); |
| 1026 | converter->exec_plan = plan; |
| 1027 | ARROW_ASSIGN_OR_RAISE(*out_schema, converter->InitializeSchema(options.field_names)); |
| 1028 | return [conv = std::move(converter)] { return (*conv)(); }; |
| 1029 | } |
| 1030 | |
| 1031 | } // namespace |
| 1032 |
no test coverage detected