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