1#include "duckdb/parser/tableref/expressionlistref.hpp"
2
3#include "duckdb/common/serializer.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8bool ExpressionListRef::Equals(const TableRef *other_) const {
9 if (!TableRef::Equals(other_)) {
10 return false;
11 }
12 auto other = (ExpressionListRef *)other_;
13 if (values.size() != other->values.size()) {
14 return false;
15 }
16 for (idx_t i = 0; i < values.size(); i++) {
17 if (values[i].size() != other->values[i].size()) {
18 return false;
19 }
20 for (idx_t j = 0; j < values[i].size(); j++) {
21 if (!values[i][j]->Equals(other->values[i][j].get())) {
22 return false;
23 }
24 }
25 }
26 return true;
27}
28
29unique_ptr<TableRef> ExpressionListRef::Copy() {
30 // value list
31 auto result = make_unique<ExpressionListRef>();
32 for (auto &val_list : values) {
33 vector<unique_ptr<ParsedExpression>> new_val_list;
34 for (auto &val : val_list) {
35 new_val_list.push_back(val->Copy());
36 }
37 result->values.push_back(move(new_val_list));
38 }
39 result->expected_names = expected_names;
40 result->expected_types = expected_types;
41 result->alias = alias;
42 return move(result);
43}
44
45void ExpressionListRef::Serialize(Serializer &serializer) {
46 TableRef::Serialize(serializer);
47 serializer.Write<idx_t>(expected_names.size());
48 for (idx_t i = 0; i < expected_names.size(); i++) {
49 serializer.WriteString(expected_names[i]);
50 }
51 serializer.Write<idx_t>(expected_types.size());
52 for (idx_t i = 0; i < expected_types.size(); i++) {
53 expected_types[i].Serialize(serializer);
54 }
55 serializer.Write<idx_t>(values.size());
56 for (idx_t i = 0; i < values.size(); i++) {
57 serializer.WriteList(values[i]);
58 }
59}
60
61unique_ptr<TableRef> ExpressionListRef::Deserialize(Deserializer &source) {
62 auto result = make_unique<ExpressionListRef>();
63 // value list
64 auto name_count = source.Read<idx_t>();
65 for (idx_t i = 0; i < name_count; i++) {
66 result->expected_names.push_back(source.Read<string>());
67 }
68 auto type_count = source.Read<idx_t>();
69 for (idx_t i = 0; i < type_count; i++) {
70 result->expected_types.push_back(SQLType::Deserialize(source));
71 }
72 idx_t value_list_size = source.Read<idx_t>();
73 for (idx_t i = 0; i < value_list_size; i++) {
74 vector<unique_ptr<ParsedExpression>> value_list;
75 source.ReadList<ParsedExpression>(value_list);
76 result->values.push_back(move(value_list));
77 }
78 return move(result);
79}
80