1#include "duckdb/execution/operator/scan/physical_chunk_scan.hpp"
2#include "duckdb/execution/physical_plan_generator.hpp"
3#include "duckdb/planner/operator/logical_explain.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) {
9 assert(op.children.size() == 1);
10 auto logical_plan_opt = op.children[0]->ToString();
11 auto plan = CreatePlan(*op.children[0]);
12
13 op.physical_plan = plan->ToString();
14
15 // the output of the explain
16 vector<string> keys = {"logical_plan", "logical_opt", "physical_plan"};
17 vector<string> values = {op.logical_plan_unopt, logical_plan_opt, op.physical_plan};
18 // create a ChunkCollection from the output
19 auto collection = make_unique<ChunkCollection>();
20
21 DataChunk chunk;
22 chunk.Initialize(op.types);
23 for (idx_t i = 0; i < keys.size(); i++) {
24 chunk.SetValue(0, chunk.size(), Value(keys[i]));
25 chunk.SetValue(1, chunk.size(), Value(values[i]));
26 chunk.SetCardinality(chunk.size() + 1);
27 if (chunk.size() == STANDARD_VECTOR_SIZE) {
28 collection->Append(chunk);
29 chunk.Reset();
30 }
31 }
32 collection->Append(chunk);
33
34 // create a chunk scan to output the result
35 auto chunk_scan = make_unique<PhysicalChunkScan>(op.types, PhysicalOperatorType::CHUNK_SCAN);
36 chunk_scan->owned_collection = move(collection);
37 chunk_scan->collection = chunk_scan->owned_collection.get();
38 return move(chunk_scan);
39}
40