1#include "duckdb/parser/query_node.hpp"
2
3#include "duckdb/parser/query_node/select_node.hpp"
4#include "duckdb/parser/query_node/set_operation_node.hpp"
5#include "duckdb/parser/query_node/recursive_cte_node.hpp"
6
7using namespace duckdb;
8using namespace std;
9
10bool QueryNode::Equals(const QueryNode *other) const {
11 if (!other) {
12 return false;
13 }
14 if (this == other) {
15 return true;
16 }
17 if (other->type != this->type) {
18 return false;
19 }
20 if (modifiers.size() != other->modifiers.size()) {
21 return false;
22 }
23 for (idx_t i = 0; i < modifiers.size(); i++) {
24 if (!modifiers[i]->Equals(other->modifiers[i].get())) {
25 return false;
26 }
27 }
28 return other->type == type;
29}
30
31void QueryNode::CopyProperties(QueryNode &other) {
32 for (auto &modifier : modifiers) {
33 other.modifiers.push_back(modifier->Copy());
34 }
35}
36
37void QueryNode::Serialize(Serializer &serializer) {
38 serializer.Write<QueryNodeType>(type);
39 serializer.Write<idx_t>(modifiers.size());
40 for (idx_t i = 0; i < modifiers.size(); i++) {
41 modifiers[i]->Serialize(serializer);
42 }
43}
44
45unique_ptr<QueryNode> QueryNode::Deserialize(Deserializer &source) {
46 unique_ptr<QueryNode> result;
47 auto type = source.Read<QueryNodeType>();
48 auto modifier_count = source.Read<idx_t>();
49 vector<unique_ptr<ResultModifier>> modifiers;
50 for (idx_t i = 0; i < modifier_count; i++) {
51 modifiers.push_back(ResultModifier::Deserialize(source));
52 }
53 switch (type) {
54 case QueryNodeType::SELECT_NODE:
55 result = SelectNode::Deserialize(source);
56 break;
57 case QueryNodeType::SET_OPERATION_NODE:
58 result = SetOperationNode::Deserialize(source);
59 break;
60 case QueryNodeType::RECURSIVE_CTE_NODE:
61 result = RecursiveCTENode::Deserialize(source);
62 break;
63 default:
64 throw SerializationException("Could not deserialize Query Node: unknown type!");
65 }
66 result->modifiers = move(modifiers);
67 return result;
68}
69