1#include "duckdb/parser/tableref/basetableref.hpp"
2
3#include "duckdb/common/field_writer.hpp"
4#include "duckdb/parser/keyword_helper.hpp"
5#include "duckdb/common/serializer/format_serializer.hpp"
6#include "duckdb/common/serializer/format_deserializer.hpp"
7
8namespace duckdb {
9
10string BaseTableRef::ToString() const {
11 string result;
12 result += catalog_name.empty() ? "" : (KeywordHelper::WriteOptionallyQuoted(text: catalog_name) + ".");
13 result += schema_name.empty() ? "" : (KeywordHelper::WriteOptionallyQuoted(text: schema_name) + ".");
14 result += KeywordHelper::WriteOptionallyQuoted(text: table_name);
15 return BaseToString(result, column_name_alias);
16}
17
18bool BaseTableRef::Equals(const TableRef &other_p) const {
19 if (!TableRef::Equals(other: other_p)) {
20 return false;
21 }
22 auto &other = other_p.Cast<BaseTableRef>();
23 return other.catalog_name == catalog_name && other.schema_name == schema_name && other.table_name == table_name &&
24 column_name_alias == other.column_name_alias;
25}
26
27void BaseTableRef::Serialize(FieldWriter &writer) const {
28 writer.WriteString(val: schema_name);
29 writer.WriteString(val: table_name);
30 writer.WriteList<string>(elements: column_name_alias);
31 writer.WriteString(val: catalog_name);
32}
33
34void BaseTableRef::FormatSerialize(FormatSerializer &serializer) const {
35 TableRef::FormatSerialize(serializer);
36 serializer.WriteProperty(tag: "schema_name", value: schema_name);
37 serializer.WriteProperty(tag: "table_name", value: table_name);
38 serializer.WriteProperty(tag: "column_name_alias", value: column_name_alias);
39 serializer.WriteProperty(tag: "catalog_name", value: catalog_name);
40}
41
42unique_ptr<TableRef> BaseTableRef::FormatDeserialize(FormatDeserializer &deserializer) {
43 auto result = make_uniq<BaseTableRef>();
44
45 deserializer.ReadProperty(tag: "schema_name", ret&: result->schema_name);
46 deserializer.ReadProperty(tag: "table_name", ret&: result->table_name);
47 deserializer.ReadProperty(tag: "column_name_alias", ret&: result->column_name_alias);
48 deserializer.ReadProperty(tag: "catalog_name", ret&: result->catalog_name);
49
50 return std::move(result);
51}
52
53unique_ptr<TableRef> BaseTableRef::Deserialize(FieldReader &reader) {
54 auto result = make_uniq<BaseTableRef>();
55
56 result->schema_name = reader.ReadRequired<string>();
57 result->table_name = reader.ReadRequired<string>();
58 result->column_name_alias = reader.ReadRequiredList<string>();
59 result->catalog_name = reader.ReadField<string>(INVALID_CATALOG);
60
61 return std::move(result);
62}
63
64unique_ptr<TableRef> BaseTableRef::Copy() {
65 auto copy = make_uniq<BaseTableRef>();
66
67 copy->catalog_name = catalog_name;
68 copy->schema_name = schema_name;
69 copy->table_name = table_name;
70 copy->column_name_alias = column_name_alias;
71 CopyProperties(target&: *copy);
72
73 return std::move(copy);
74}
75} // namespace duckdb
76