1#include "duckdb/parser/tableref/subqueryref.hpp"
2
3#include "duckdb/common/serializer.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8SubqueryRef::SubqueryRef(unique_ptr<QueryNode> subquery_p, string alias_p)
9 : TableRef(TableReferenceType::SUBQUERY), subquery(move(subquery_p)) {
10 this->alias = alias_p;
11}
12
13bool SubqueryRef::Equals(const TableRef *other_) const {
14 if (!TableRef::Equals(other_)) {
15 return false;
16 }
17 auto other = (SubqueryRef *)other_;
18 return subquery->Equals(other->subquery.get());
19}
20
21unique_ptr<TableRef> SubqueryRef::Copy() {
22 auto copy = make_unique<SubqueryRef>(subquery->Copy(), alias);
23 copy->column_name_alias = column_name_alias;
24 return move(copy);
25}
26
27void SubqueryRef::Serialize(Serializer &serializer) {
28 TableRef::Serialize(serializer);
29 subquery->Serialize(serializer);
30 assert(column_name_alias.size() <= numeric_limits<uint32_t>::max());
31 serializer.Write<uint32_t>((uint32_t)column_name_alias.size());
32 for (auto &alias : column_name_alias) {
33 serializer.WriteString(alias);
34 }
35}
36
37unique_ptr<TableRef> SubqueryRef::Deserialize(Deserializer &source) {
38 auto subquery = QueryNode::Deserialize(source);
39 if (!subquery) {
40 return nullptr;
41 }
42 auto result = make_unique<SubqueryRef>(move(subquery));
43 idx_t column_count = (idx_t)source.Read<uint32_t>();
44 for (idx_t i = 0; i < column_count; i++) {
45 result->column_name_alias.push_back(source.Read<string>());
46 }
47 return move(result);
48}
49