1#include "duckdb/parser/tableref/joinref.hpp"
2
3#include "duckdb/common/serializer.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8bool JoinRef::Equals(const TableRef *other_) const {
9 if (!TableRef::Equals(other_)) {
10 return false;
11 }
12 auto other = (JoinRef *)other_;
13 if (using_columns.size() != other->using_columns.size()) {
14 return false;
15 }
16 for (idx_t i = 0; i < using_columns.size(); i++) {
17 if (using_columns[i] != other->using_columns[i]) {
18 return false;
19 }
20 }
21 return left->Equals(other->left.get()) && right->Equals(other->right.get()) &&
22 BaseExpression::Equals(condition.get(), other->condition.get()) && type == other->type;
23}
24
25unique_ptr<TableRef> JoinRef::Copy() {
26 auto copy = make_unique<JoinRef>();
27 copy->left = left->Copy();
28 copy->right = right->Copy();
29 if (condition) {
30 copy->condition = condition->Copy();
31 }
32 copy->type = type;
33 copy->alias = alias;
34 copy->using_columns = using_columns;
35 return move(copy);
36}
37
38void JoinRef::Serialize(Serializer &serializer) {
39 TableRef::Serialize(serializer);
40
41 left->Serialize(serializer);
42 right->Serialize(serializer);
43 serializer.WriteOptional(condition);
44 serializer.Write<JoinType>(type);
45 assert(using_columns.size() <= numeric_limits<uint32_t>::max());
46 serializer.Write<uint32_t>((uint32_t)using_columns.size());
47 for (auto &using_column : using_columns) {
48 serializer.WriteString(using_column);
49 }
50}
51
52unique_ptr<TableRef> JoinRef::Deserialize(Deserializer &source) {
53 auto result = make_unique<JoinRef>();
54
55 result->left = TableRef::Deserialize(source);
56 result->right = TableRef::Deserialize(source);
57 result->condition = source.ReadOptional<ParsedExpression>();
58 result->type = source.Read<JoinType>();
59 auto count = source.Read<uint32_t>();
60 for (idx_t i = 0; i < count; i++) {
61 result->using_columns.push_back(source.Read<string>());
62 }
63 return move(result);
64}
65