1#include "duckdb/catalog/catalog_entry/view_catalog_entry.hpp"
2
3#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
4#include "duckdb/common/exception.hpp"
5#include "duckdb/common/serializer.hpp"
6#include "duckdb/parser/parsed_data/create_view_info.hpp"
7
8#include <algorithm>
9
10using namespace duckdb;
11using namespace std;
12
13void ViewCatalogEntry::Initialize(CreateViewInfo *info) {
14 query = move(info->query);
15 this->aliases = info->aliases;
16 this->types = info->types;
17 this->temporary = info->temporary;
18}
19
20ViewCatalogEntry::ViewCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateViewInfo *info)
21 : StandardEntry(CatalogType::VIEW, schema, catalog, info->view_name) {
22 Initialize(info);
23}
24
25void ViewCatalogEntry::Serialize(Serializer &serializer) {
26 serializer.WriteString(schema->name);
27 serializer.WriteString(name);
28 query->Serialize(serializer);
29 assert(aliases.size() <= numeric_limits<uint32_t>::max());
30 serializer.Write<uint32_t>((uint32_t)aliases.size());
31 for (auto &alias : aliases) {
32 serializer.WriteString(alias);
33 }
34 serializer.Write<uint32_t>((uint32_t)types.size());
35 for (auto &sql_type : types) {
36 sql_type.Serialize(serializer);
37 }
38}
39
40unique_ptr<CreateViewInfo> ViewCatalogEntry::Deserialize(Deserializer &source) {
41 auto info = make_unique<CreateViewInfo>();
42 info->schema = source.Read<string>();
43 info->view_name = source.Read<string>();
44 info->query = QueryNode::Deserialize(source);
45 auto alias_count = source.Read<uint32_t>();
46 for (uint32_t i = 0; i < alias_count; i++) {
47 info->aliases.push_back(source.Read<string>());
48 }
49 auto type_count = source.Read<uint32_t>();
50 for (uint32_t i = 0; i < type_count; i++) {
51 info->types.push_back(SQLType::Deserialize(source));
52 }
53 return info;
54}
55