1 | #include "duckdb/planner/expression/bound_case_expression.hpp" |
2 | |
3 | using namespace duckdb; |
4 | using namespace std; |
5 | |
6 | BoundCaseExpression::BoundCaseExpression(unique_ptr<Expression> check, unique_ptr<Expression> res_if_true, |
7 | unique_ptr<Expression> res_if_false) |
8 | : Expression(ExpressionType::CASE_EXPR, ExpressionClass::BOUND_CASE, res_if_true->return_type), check(move(check)), |
9 | result_if_true(move(res_if_true)), result_if_false(move(res_if_false)) { |
10 | } |
11 | |
12 | string BoundCaseExpression::ToString() const { |
13 | return "CASE WHEN (" + check->GetName() + ") THEN (" + result_if_true->GetName() + ") ELSE (" + |
14 | result_if_false->GetName() + ")" ; |
15 | } |
16 | |
17 | bool BoundCaseExpression::Equals(const BaseExpression *other_) const { |
18 | if (!BaseExpression::Equals(other_)) { |
19 | return false; |
20 | } |
21 | auto other = (BoundCaseExpression *)other_; |
22 | if (!Expression::Equals(check.get(), other->check.get())) { |
23 | return false; |
24 | } |
25 | if (!Expression::Equals(result_if_true.get(), other->result_if_true.get())) { |
26 | return false; |
27 | } |
28 | if (!Expression::Equals(result_if_false.get(), other->result_if_false.get())) { |
29 | return false; |
30 | } |
31 | return true; |
32 | } |
33 | |
34 | unique_ptr<Expression> BoundCaseExpression::Copy() { |
35 | auto new_case = make_unique<BoundCaseExpression>(check->Copy(), result_if_true->Copy(), result_if_false->Copy()); |
36 | new_case->CopyProperties(*this); |
37 | return move(new_case); |
38 | } |
39 | |