| 1 | #include "duckdb/parser/statement/create_statement.hpp" |
|---|---|
| 2 | #include "duckdb/parser/transformer.hpp" |
| 3 | #include "duckdb/parser/parsed_data/create_view_info.hpp" |
| 4 | |
| 5 | using namespace duckdb; |
| 6 | using namespace std; |
| 7 | |
| 8 | unique_ptr<CreateStatement> Transformer::TransformCreateView(PGNode *node) { |
| 9 | assert(node); |
| 10 | assert(node->type == T_PGViewStmt); |
| 11 | |
| 12 | auto stmt = reinterpret_cast<PGViewStmt *>(node); |
| 13 | assert(stmt); |
| 14 | assert(stmt->view); |
| 15 | |
| 16 | auto result = make_unique<CreateStatement>(); |
| 17 | auto info = make_unique<CreateViewInfo>(); |
| 18 | |
| 19 | if (stmt->view->schemaname) { |
| 20 | info->schema = stmt->view->schemaname; |
| 21 | } |
| 22 | info->view_name = stmt->view->relname; |
| 23 | info->temporary = !stmt->view->relpersistence; |
| 24 | if (info->temporary) { |
| 25 | info->schema = TEMP_SCHEMA; |
| 26 | } |
| 27 | info->on_conflict = stmt->replace ? OnCreateConflict::REPLACE : OnCreateConflict::ERROR; |
| 28 | |
| 29 | info->query = TransformSelectNode((PGSelectStmt *)stmt->query); |
| 30 | |
| 31 | if (stmt->aliases && stmt->aliases->length > 0) { |
| 32 | for (auto c = stmt->aliases->head; c != NULL; c = lnext(c)) { |
| 33 | auto node = reinterpret_cast<PGNode *>(c->data.ptr_value); |
| 34 | switch (node->type) { |
| 35 | case T_PGString: { |
| 36 | auto val = (PGValue *)node; |
| 37 | info->aliases.push_back(string(val->val.str)); |
| 38 | break; |
| 39 | } |
| 40 | default: |
| 41 | throw NotImplementedException("View projection type"); |
| 42 | } |
| 43 | } |
| 44 | if (info->aliases.size() < 1) { |
| 45 | throw ParserException("Need at least one column name in CREATE VIEW projection list"); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | if (stmt->options && stmt->options->length > 0) { |
| 50 | throw NotImplementedException("VIEW options"); |
| 51 | } |
| 52 | |
| 53 | if (stmt->withCheckOption != PGViewCheckOption::PG_NO_CHECK_OPTION) { |
| 54 | throw NotImplementedException("VIEW CHECK options"); |
| 55 | } |
| 56 | result->info = move(info); |
| 57 | return result; |
| 58 | } |
| 59 |