1#include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
2#include "duckdb/execution/operator/schema/physical_create_table.hpp"
3#include "duckdb/execution/physical_plan_generator.hpp"
4#include "duckdb/planner/expression/bound_function_expression.hpp"
5#include "duckdb/planner/expression_iterator.hpp"
6#include "duckdb/planner/operator/logical_create_table.hpp"
7
8using namespace duckdb;
9using namespace std;
10
11static void ExtractDependencies(Expression &expr, unordered_set<CatalogEntry *> &dependencies) {
12 if (expr.type == ExpressionType::BOUND_FUNCTION) {
13 auto &function = (BoundFunctionExpression &)expr;
14 if (function.function.dependency) {
15 function.function.dependency(function, dependencies);
16 }
17 }
18 ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { ExtractDependencies(child, dependencies); });
19}
20
21unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalCreateTable &op) {
22 // extract dependencies from any default values
23 for (auto &default_value : op.info->bound_defaults) {
24 if (default_value) {
25 ExtractDependencies(*default_value, op.info->dependencies);
26 }
27 }
28 auto create = make_unique<PhysicalCreateTable>(op, op.schema, move(op.info));
29 if (op.children.size() > 0) {
30 assert(op.children.size() == 1);
31 auto plan = CreatePlan(*op.children[0]);
32 create->children.push_back(move(plan));
33 }
34 return move(create);
35}
36