1#include "duckdb/parser/expression/case_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8CaseExpression::CaseExpression() : ParsedExpression(ExpressionType::CASE_EXPR, ExpressionClass::CASE) {
9}
10
11string CaseExpression::ToString() const {
12 return "CASE WHEN (" + check->ToString() + ") THEN (" + result_if_true->ToString() + ") ELSE (" +
13 result_if_false->ToString() + ")";
14}
15
16bool CaseExpression::Equals(const CaseExpression *a, const CaseExpression *b) {
17 if (!a->check->Equals(b->check.get())) {
18 return false;
19 }
20 if (!a->result_if_true->Equals(b->result_if_true.get())) {
21 return false;
22 }
23 if (!a->result_if_false->Equals(b->result_if_false.get())) {
24 return false;
25 }
26 return true;
27}
28
29unique_ptr<ParsedExpression> CaseExpression::Copy() const {
30 auto copy = make_unique<CaseExpression>();
31 copy->CopyProperties(*this);
32 copy->check = check->Copy();
33 copy->result_if_true = result_if_true->Copy();
34 copy->result_if_false = result_if_false->Copy();
35 return move(copy);
36}
37
38void CaseExpression::Serialize(Serializer &serializer) {
39 ParsedExpression::Serialize(serializer);
40 check->Serialize(serializer);
41 result_if_true->Serialize(serializer);
42 result_if_false->Serialize(serializer);
43}
44
45unique_ptr<ParsedExpression> CaseExpression::Deserialize(ExpressionType type, Deserializer &source) {
46 auto expression = make_unique<CaseExpression>();
47 expression->check = ParsedExpression::Deserialize(source);
48 expression->result_if_true = ParsedExpression::Deserialize(source);
49 expression->result_if_false = ParsedExpression::Deserialize(source);
50 return move(expression);
51}
52