1#include "duckdb/main/relation/view_relation.hpp"
2#include "duckdb/parser/tableref/basetableref.hpp"
3#include "duckdb/parser/query_node/select_node.hpp"
4#include "duckdb/parser/expression/star_expression.hpp"
5#include "duckdb/main/client_context.hpp"
6#include "duckdb/parser/parser.hpp"
7
8namespace duckdb {
9
10ViewRelation::ViewRelation(ClientContext &context, string schema_name_p, string view_name_p)
11 : Relation(context, RelationType::VIEW_RELATION), schema_name(move(schema_name_p)), view_name(move(view_name_p)) {
12 context.TryBindRelation(*this, this->columns);
13}
14
15unique_ptr<QueryNode> ViewRelation::GetQueryNode() {
16 auto result = make_unique<SelectNode>();
17 result->select_list.push_back(make_unique<StarExpression>());
18 result->from_table = GetTableRef();
19 return move(result);
20}
21
22unique_ptr<TableRef> ViewRelation::GetTableRef() {
23 auto table_ref = make_unique<BaseTableRef>();
24 table_ref->schema_name = schema_name;
25 table_ref->table_name = view_name;
26 return move(table_ref);
27}
28
29string ViewRelation::GetAlias() {
30 return view_name;
31}
32
33const vector<ColumnDefinition> &ViewRelation::Columns() {
34 return columns;
35}
36
37string ViewRelation::ToString(idx_t depth) {
38 return RenderWhitespace(depth) + "View [" + view_name + "]";
39}
40
41} // namespace duckdb
42