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