1 | #include "duckdb/parser/statement/logical_plan_statement.hpp" |
---|---|
2 | #include "duckdb/planner/binder.hpp" |
3 | #include <algorithm> |
4 | |
5 | namespace duckdb { |
6 | |
7 | idx_t GetMaxTableIndex(LogicalOperator &op) { |
8 | idx_t result = 0; |
9 | for (auto &child : op.children) { |
10 | auto max_child_index = GetMaxTableIndex(op&: *child); |
11 | result = MaxValue<idx_t>(a: result, b: max_child_index); |
12 | } |
13 | auto indexes = op.GetTableIndex(); |
14 | for (auto &index : indexes) { |
15 | result = MaxValue<idx_t>(a: result, b: index); |
16 | } |
17 | return result; |
18 | } |
19 | |
20 | BoundStatement Binder::Bind(LogicalPlanStatement &stmt) { |
21 | BoundStatement result; |
22 | result.types = stmt.plan->types; |
23 | for (idx_t i = 0; i < result.types.size(); i++) { |
24 | result.names.push_back(x: StringUtil::Format(fmt_str: "col%d", params: i)); |
25 | } |
26 | result.plan = std::move(stmt.plan); |
27 | properties.allow_stream_result = true; |
28 | properties.return_type = StatementReturnType::QUERY_RESULT; // TODO could also be something else |
29 | |
30 | if (parent) { |
31 | throw InternalException("LogicalPlanStatement should be bound in root binder"); |
32 | } |
33 | bound_tables = GetMaxTableIndex(op&: *result.plan) + 1; |
34 | return result; |
35 | } |
36 | |
37 | } // namespace duckdb |
38 |