1#include "duckdb/parser/expression/comparison_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/field_writer.hpp"
5#include "duckdb/parser/expression/cast_expression.hpp"
6
7#include "duckdb/common/serializer/format_serializer.hpp"
8#include "duckdb/common/serializer/format_deserializer.hpp"
9
10namespace duckdb {
11
12ComparisonExpression::ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
13 unique_ptr<ParsedExpression> right)
14 : ParsedExpression(type, ExpressionClass::COMPARISON), left(std::move(left)), right(std::move(right)) {
15}
16
17string ComparisonExpression::ToString() const {
18 return ToString<ComparisonExpression, ParsedExpression>(entry: *this);
19}
20
21bool ComparisonExpression::Equal(const ComparisonExpression &a, const ComparisonExpression &b) {
22 if (!a.left->Equals(other: *b.left)) {
23 return false;
24 }
25 if (!a.right->Equals(other: *b.right)) {
26 return false;
27 }
28 return true;
29}
30
31unique_ptr<ParsedExpression> ComparisonExpression::Copy() const {
32 auto copy = make_uniq<ComparisonExpression>(args: type, args: left->Copy(), args: right->Copy());
33 copy->CopyProperties(other: *this);
34 return std::move(copy);
35}
36
37void ComparisonExpression::Serialize(FieldWriter &writer) const {
38 writer.WriteSerializable(element: *left);
39 writer.WriteSerializable(element: *right);
40}
41
42unique_ptr<ParsedExpression> ComparisonExpression::Deserialize(ExpressionType type, FieldReader &reader) {
43 auto left_child = reader.ReadRequiredSerializable<ParsedExpression>();
44 auto right_child = reader.ReadRequiredSerializable<ParsedExpression>();
45 return make_uniq<ComparisonExpression>(args&: type, args: std::move(left_child), args: std::move(right_child));
46}
47
48void ComparisonExpression::FormatSerialize(FormatSerializer &serializer) const {
49 ParsedExpression::FormatSerialize(serializer);
50 serializer.WriteProperty(tag: "left", value&: *left);
51 serializer.WriteProperty(tag: "right", value&: *right);
52}
53
54unique_ptr<ParsedExpression> ComparisonExpression::FormatDeserialize(ExpressionType type,
55 FormatDeserializer &deserializer) {
56 auto left = deserializer.ReadProperty<unique_ptr<ParsedExpression>>(tag: "left");
57 auto right = deserializer.ReadProperty<unique_ptr<ParsedExpression>>(tag: "right");
58 return make_uniq<ComparisonExpression>(args&: type, args: std::move(left), args: std::move(right));
59}
60
61} // namespace duckdb
62