[[substrait::export]]
| 541 | |
| 542 | // [[substrait::export]] |
| 543 | std::shared_ptr<arrow::Table> ExecPlan_run_substrait( |
| 544 | const std::shared_ptr<acero::ExecPlan>& plan, |
| 545 | const std::shared_ptr<arrow::Buffer>& serialized_plan) { |
| 546 | std::vector<std::shared_ptr<AccumulatingConsumer>> consumers; |
| 547 | |
| 548 | std::function<std::shared_ptr<acero::SinkNodeConsumer>()> consumer_factory = [&] { |
| 549 | consumers.emplace_back(new AccumulatingConsumer()); |
| 550 | return consumers.back(); |
| 551 | }; |
| 552 | |
| 553 | arrow::Result<std::vector<acero::Declaration>> maybe_decls = |
| 554 | ValueOrStop(arrow::engine::DeserializePlans(*serialized_plan, consumer_factory)); |
| 555 | std::vector<acero::Declaration> decls = std::move(ValueOrStop(maybe_decls)); |
| 556 | |
| 557 | // For now, the Substrait plan must include a 'read' that points to |
| 558 | // a Parquet file (instead of using a source node create in Arrow) |
| 559 | for (const acero::Declaration& decl : decls) { |
| 560 | auto node = decl.AddToPlan(plan.get()); |
| 561 | StopIfNotOk(node.status()); |
| 562 | } |
| 563 | |
| 564 | StopIfNotOk(plan->Validate()); |
| 565 | plan->StartProducing(); |
| 566 | StopIfNotOk(plan->finished().status()); |
| 567 | |
| 568 | std::vector<std::shared_ptr<arrow::RecordBatch>> all_batches; |
| 569 | for (const auto& consumer : consumers) { |
| 570 | for (const auto& batch : consumer->batches()) { |
| 571 | all_batches.push_back(batch); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return ValueOrStop(arrow::Table::FromRecordBatches(std::move(all_batches))); |
| 576 | } |
| 577 | |
| 578 | #endif |
no test coverage detected