1#include "duckdb/parser/expression/cast_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8CastExpression::CastExpression(SQLType target, unique_ptr<ParsedExpression> child)
9 : ParsedExpression(ExpressionType::OPERATOR_CAST, ExpressionClass::CAST), cast_type(target) {
10 assert(child);
11 this->child = move(child);
12}
13
14string CastExpression::ToString() const {
15 return "CAST[" + SQLTypeToString(cast_type) + "](" + child->ToString() + ")";
16}
17
18bool CastExpression::Equals(const CastExpression *a, const CastExpression *b) {
19 if (!a->child->Equals(b->child.get())) {
20 return false;
21 }
22 if (a->cast_type != b->cast_type) {
23 return false;
24 }
25 return true;
26}
27
28unique_ptr<ParsedExpression> CastExpression::Copy() const {
29 auto copy = make_unique<CastExpression>(cast_type, child->Copy());
30 copy->CopyProperties(*this);
31 return move(copy);
32}
33
34void CastExpression::Serialize(Serializer &serializer) {
35 ParsedExpression::Serialize(serializer);
36 child->Serialize(serializer);
37 cast_type.Serialize(serializer);
38}
39
40unique_ptr<ParsedExpression> CastExpression::Deserialize(ExpressionType type, Deserializer &source) {
41 auto child = ParsedExpression::Deserialize(source);
42 auto cast_type = SQLType::Deserialize(source);
43 return make_unique_base<ParsedExpression, CastExpression>(cast_type, move(child));
44}
45