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