1#include "duckdb/parser/tableref/table_function_ref.hpp"
2#include "duckdb/common/vector.hpp"
3#include "duckdb/common/field_writer.hpp"
4#include "duckdb/common/serializer/format_serializer.hpp"
5#include "duckdb/common/serializer/format_deserializer.hpp"
6
7namespace duckdb {
8
9TableFunctionRef::TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
10}
11
12string TableFunctionRef::ToString() const {
13 return BaseToString(result: function->ToString(), column_name_alias);
14}
15
16bool TableFunctionRef::Equals(const TableRef &other_p) const {
17 if (!TableRef::Equals(other: other_p)) {
18 return false;
19 }
20 auto &other = other_p.Cast<TableFunctionRef>();
21 return function->Equals(other: *other.function);
22}
23
24void TableFunctionRef::Serialize(FieldWriter &writer) const {
25 writer.WriteSerializable(element: *function);
26 writer.WriteString(val: alias);
27 writer.WriteList<string>(elements: column_name_alias);
28}
29
30void TableFunctionRef::FormatSerialize(FormatSerializer &serializer) const {
31 TableRef::FormatSerialize(serializer);
32 serializer.WriteProperty(tag: "function", value: function);
33 serializer.WriteProperty(tag: "alias", value: alias);
34 serializer.WriteProperty(tag: "column_name_alias", value: column_name_alias);
35}
36
37unique_ptr<TableRef> TableFunctionRef::FormatDeserialize(FormatDeserializer &deserializer) {
38 auto result = make_uniq<TableFunctionRef>();
39 deserializer.ReadProperty(tag: "function", ret&: result->function);
40 deserializer.ReadProperty(tag: "alias", ret&: result->alias);
41 deserializer.ReadProperty(tag: "column_name_alias", ret&: result->column_name_alias);
42 return std::move(result);
43}
44
45unique_ptr<TableRef> TableFunctionRef::Deserialize(FieldReader &reader) {
46 auto result = make_uniq<TableFunctionRef>();
47 result->function = reader.ReadRequiredSerializable<ParsedExpression>();
48 result->alias = reader.ReadRequired<string>();
49 result->column_name_alias = reader.ReadRequiredList<string>();
50 return std::move(result);
51}
52
53unique_ptr<TableRef> TableFunctionRef::Copy() {
54 auto copy = make_uniq<TableFunctionRef>();
55
56 copy->function = function->Copy();
57 copy->column_name_alias = column_name_alias;
58 CopyProperties(target&: *copy);
59
60 return std::move(copy);
61}
62
63} // namespace duckdb
64