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