1#include "duckdb/parser/expression/operator_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/field_writer.hpp"
5
6#include "duckdb/common/serializer/format_serializer.hpp"
7#include "duckdb/common/serializer/format_deserializer.hpp"
8
9namespace duckdb {
10
11OperatorExpression::OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
12 unique_ptr<ParsedExpression> right)
13 : ParsedExpression(type, ExpressionClass::OPERATOR) {
14 if (left) {
15 children.push_back(x: std::move(left));
16 }
17 if (right) {
18 children.push_back(x: std::move(right));
19 }
20}
21
22OperatorExpression::OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children)
23 : ParsedExpression(type, ExpressionClass::OPERATOR), children(std::move(children)) {
24}
25
26string OperatorExpression::ToString() const {
27 return ToString<OperatorExpression, ParsedExpression>(entry: *this);
28}
29
30bool OperatorExpression::Equal(const OperatorExpression &a, const OperatorExpression &b) {
31 if (a.children.size() != b.children.size()) {
32 return false;
33 }
34 for (idx_t i = 0; i < a.children.size(); i++) {
35 if (!a.children[i]->Equals(other: *b.children[i])) {
36 return false;
37 }
38 }
39 return true;
40}
41
42unique_ptr<ParsedExpression> OperatorExpression::Copy() const {
43 auto copy = make_uniq<OperatorExpression>(args: type);
44 copy->CopyProperties(other: *this);
45 for (auto &it : children) {
46 copy->children.push_back(x: it->Copy());
47 }
48 return std::move(copy);
49}
50
51void OperatorExpression::Serialize(FieldWriter &writer) const {
52 writer.WriteSerializableList(elements: children);
53}
54
55unique_ptr<ParsedExpression> OperatorExpression::Deserialize(ExpressionType type, FieldReader &reader) {
56 auto expression = make_uniq<OperatorExpression>(args&: type);
57 expression->children = reader.ReadRequiredSerializableList<ParsedExpression>();
58 return std::move(expression);
59}
60
61void OperatorExpression::FormatSerialize(FormatSerializer &serializer) const {
62 ParsedExpression::FormatSerialize(serializer);
63 serializer.WriteProperty(tag: "children", value: children);
64}
65
66unique_ptr<ParsedExpression> OperatorExpression::FormatDeserialize(ExpressionType type,
67 FormatDeserializer &deserializer) {
68 auto expression = make_uniq<OperatorExpression>(args&: type);
69 expression->children = deserializer.ReadProperty<vector<unique_ptr<ParsedExpression>>>(tag: "children");
70 return std::move(expression);
71}
72
73} // namespace duckdb
74