1#include "duckdb/planner/logical_operator.hpp"
2
3#include "duckdb/common/printer.hpp"
4#include "duckdb/common/string_util.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9string LogicalOperator::ParamsToString() const {
10 string result = "";
11 if (expressions.size() > 0) {
12 result += "[";
13 result += StringUtil::Join(expressions, expressions.size(), ", ",
14 [](const unique_ptr<Expression> &expression) { return expression->GetName(); });
15 result += "]";
16 }
17
18 return result;
19}
20
21void LogicalOperator::ResolveOperatorTypes() {
22 // if (types.size() > 0) {
23 // // types already resolved for this node
24 // return;
25 // }
26 types.clear();
27 // first resolve child types
28 for (auto &child : children) {
29 child->ResolveOperatorTypes();
30 }
31 // now resolve the types for this operator
32 ResolveTypes();
33}
34
35vector<ColumnBinding> LogicalOperator::GenerateColumnBindings(idx_t table_idx, idx_t column_count) {
36 vector<ColumnBinding> result;
37 for (idx_t i = 0; i < column_count; i++) {
38 result.push_back(ColumnBinding(table_idx, i));
39 }
40 return result;
41}
42
43vector<TypeId> LogicalOperator::MapTypes(vector<TypeId> types, vector<idx_t> projection_map) {
44 if (projection_map.size() == 0) {
45 return types;
46 } else {
47 vector<TypeId> result_types;
48 for (auto index : projection_map) {
49 result_types.push_back(types[index]);
50 }
51 return result_types;
52 }
53}
54
55vector<ColumnBinding> LogicalOperator::MapBindings(vector<ColumnBinding> bindings, vector<idx_t> projection_map) {
56 if (projection_map.size() == 0) {
57 return bindings;
58 } else {
59 vector<ColumnBinding> result_bindings;
60 for (auto index : projection_map) {
61 result_bindings.push_back(bindings[index]);
62 }
63 return result_bindings;
64 }
65}
66
67string LogicalOperator::ToString(idx_t depth) const {
68 string result = LogicalOperatorToString(type);
69 result += ParamsToString();
70 if (children.size() > 0) {
71 for (idx_t i = 0; i < children.size(); i++) {
72 result += "\n" + string(depth * 4, ' ');
73 auto &child = children[i];
74 result += child->ToString(depth + 1);
75 }
76 result += "";
77 }
78 return result;
79}
80
81void LogicalOperator::Print() {
82 Printer::Print(ToString());
83}
84