| 1 | #include "duckdb/planner/expression/bound_between_expression.hpp" |
| 2 | #include "duckdb/parser/expression/between_expression.hpp" |
| 3 | #include "duckdb/common/field_writer.hpp" |
| 4 | |
| 5 | namespace duckdb { |
| 6 | |
| 7 | BoundBetweenExpression::BoundBetweenExpression(unique_ptr<Expression> input, unique_ptr<Expression> lower, |
| 8 | unique_ptr<Expression> upper, bool lower_inclusive, bool upper_inclusive) |
| 9 | : Expression(ExpressionType::COMPARE_BETWEEN, ExpressionClass::BOUND_BETWEEN, LogicalType::BOOLEAN), |
| 10 | input(std::move(input)), lower(std::move(lower)), upper(std::move(upper)), lower_inclusive(lower_inclusive), |
| 11 | upper_inclusive(upper_inclusive) { |
| 12 | } |
| 13 | |
| 14 | string BoundBetweenExpression::ToString() const { |
| 15 | return BetweenExpression::ToString<BoundBetweenExpression, Expression>(entry: *this); |
| 16 | } |
| 17 | |
| 18 | bool BoundBetweenExpression::Equals(const BaseExpression &other_p) const { |
| 19 | if (!Expression::Equals(other: other_p)) { |
| 20 | return false; |
| 21 | } |
| 22 | auto &other = other_p.Cast<BoundBetweenExpression>(); |
| 23 | if (!Expression::Equals(left: *input, right: *other.input)) { |
| 24 | return false; |
| 25 | } |
| 26 | if (!Expression::Equals(left: *lower, right: *other.lower)) { |
| 27 | return false; |
| 28 | } |
| 29 | if (!Expression::Equals(left: *upper, right: *other.upper)) { |
| 30 | return false; |
| 31 | } |
| 32 | return lower_inclusive == other.lower_inclusive && upper_inclusive == other.upper_inclusive; |
| 33 | } |
| 34 | |
| 35 | unique_ptr<Expression> BoundBetweenExpression::Copy() { |
| 36 | auto copy = make_uniq<BoundBetweenExpression>(args: input->Copy(), args: lower->Copy(), args: upper->Copy(), args&: lower_inclusive, |
| 37 | args&: upper_inclusive); |
| 38 | copy->CopyProperties(other&: *this); |
| 39 | return std::move(copy); |
| 40 | } |
| 41 | |
| 42 | void BoundBetweenExpression::Serialize(FieldWriter &writer) const { |
| 43 | writer.WriteOptional(element: input); |
| 44 | writer.WriteOptional(element: lower); |
| 45 | writer.WriteOptional(element: upper); |
| 46 | writer.WriteField(element: lower_inclusive); |
| 47 | writer.WriteField(element: upper_inclusive); |
| 48 | } |
| 49 | |
| 50 | unique_ptr<Expression> BoundBetweenExpression::Deserialize(ExpressionDeserializationState &state, FieldReader &reader) { |
| 51 | auto input = reader.ReadOptional<Expression>(default_value: nullptr, args&: state.gstate); |
| 52 | auto lower = reader.ReadOptional<Expression>(default_value: nullptr, args&: state.gstate); |
| 53 | auto upper = reader.ReadOptional<Expression>(default_value: nullptr, args&: state.gstate); |
| 54 | auto lower_inclusive = reader.ReadRequired<bool>(); |
| 55 | auto upper_inclusive = reader.ReadRequired<bool>(); |
| 56 | return make_uniq<BoundBetweenExpression>(args: std::move(input), args: std::move(lower), args: std::move(upper), args&: lower_inclusive, |
| 57 | args&: upper_inclusive); |
| 58 | } |
| 59 | |
| 60 | } // namespace duckdb |
| 61 | |