1#include "duckdb/execution/operator/filter/physical_filter.hpp"
2#include "duckdb/execution/operator/projection/physical_projection.hpp"
3#include "duckdb/execution/physical_plan_generator.hpp"
4#include "duckdb/optimizer/matcher/expression_matcher.hpp"
5#include "duckdb/planner/expression/bound_comparison_expression.hpp"
6#include "duckdb/planner/expression/bound_constant_expression.hpp"
7#include "duckdb/planner/expression/bound_reference_expression.hpp"
8#include "duckdb/planner/operator/logical_filter.hpp"
9#include "duckdb/planner/operator/logical_get.hpp"
10
11using namespace duckdb;
12using namespace std;
13
14unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalFilter &op) {
15 assert(op.children.size() == 1);
16 unique_ptr<PhysicalOperator> plan = CreatePlan(*op.children[0]);
17 if (op.expressions.size() > 0) {
18 // create a filter if there is anything to filter
19 auto filter = make_unique<PhysicalFilter>(op.children[0]->types, move(op.expressions));
20 filter->children.push_back(move(plan));
21 plan = move(filter);
22 }
23 if (op.projection_map.size() > 0) {
24 // there is a projection map, generate a physical projection
25 vector<unique_ptr<Expression>> select_list;
26 for (idx_t i = 0; i < op.projection_map.size(); i++) {
27 select_list.push_back(make_unique<BoundReferenceExpression>(op.types[i], op.projection_map[i]));
28 }
29 auto proj = make_unique<PhysicalProjection>(op.types, move(select_list));
30 proj->children.push_back(move(plan));
31 plan = move(proj);
32 }
33 return plan;
34}
35