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(const std::shared_ptr<ClientContext> &context, string schema_name_p, string view_name_p)
11 : Relation(context, RelationType::VIEW_RELATION), schema_name(std::move(schema_name_p)),
12 view_name(std::move(view_name_p)) {
13 context->TryBindRelation(relation&: *this, result_columns&: this->columns);
14}
15
16unique_ptr<QueryNode> ViewRelation::GetQueryNode() {
17 auto result = make_uniq<SelectNode>();
18 result->select_list.push_back(x: make_uniq<StarExpression>());
19 result->from_table = GetTableRef();
20 return std::move(result);
21}
22
23unique_ptr<TableRef> ViewRelation::GetTableRef() {
24 auto table_ref = make_uniq<BaseTableRef>();
25 table_ref->schema_name = schema_name;
26 table_ref->table_name = view_name;
27 return std::move(table_ref);
28}
29
30string ViewRelation::GetAlias() {
31 return view_name;
32}
33
34const vector<ColumnDefinition> &ViewRelation::Columns() {
35 return columns;
36}
37
38string ViewRelation::ToString(idx_t depth) {
39 return RenderWhitespace(depth) + "View [" + view_name + "]";
40}
41
42} // namespace duckdb
43