1#include "duckdb/parser/expression/collate_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/field_writer.hpp"
5
6#include "duckdb/common/serializer/format_serializer.hpp"
7#include "duckdb/common/serializer/format_deserializer.hpp"
8
9namespace duckdb {
10
11CollateExpression::CollateExpression(string collation_p, unique_ptr<ParsedExpression> child)
12 : ParsedExpression(ExpressionType::COLLATE, ExpressionClass::COLLATE), collation(std::move(collation_p)) {
13 D_ASSERT(child);
14 this->child = std::move(child);
15}
16
17string CollateExpression::ToString() const {
18 return StringUtil::Format(fmt_str: "%s COLLATE %s", params: child->ToString(), params: SQLIdentifier(collation));
19}
20
21bool CollateExpression::Equal(const CollateExpression &a, const CollateExpression &b) {
22 if (!a.child->Equals(other: *b.child)) {
23 return false;
24 }
25 if (a.collation != b.collation) {
26 return false;
27 }
28 return true;
29}
30
31unique_ptr<ParsedExpression> CollateExpression::Copy() const {
32 auto copy = make_uniq<CollateExpression>(args: collation, args: child->Copy());
33 copy->CopyProperties(other: *this);
34 return std::move(copy);
35}
36
37void CollateExpression::Serialize(FieldWriter &writer) const {
38 writer.WriteSerializable(element: *child);
39 writer.WriteString(val: collation);
40}
41
42unique_ptr<ParsedExpression> CollateExpression::Deserialize(ExpressionType type, FieldReader &reader) {
43 auto child = reader.ReadRequiredSerializable<ParsedExpression>();
44 auto collation = reader.ReadRequired<string>();
45 return make_uniq_base<ParsedExpression, CollateExpression>(args&: collation, args: std::move(child));
46}
47
48void CollateExpression::FormatSerialize(FormatSerializer &serializer) const {
49 ParsedExpression::FormatSerialize(serializer);
50 serializer.WriteProperty(tag: "child", value&: *child);
51 serializer.WriteProperty(tag: "collation", value: collation);
52}
53
54unique_ptr<ParsedExpression> CollateExpression::FormatDeserialize(ExpressionType type,
55 FormatDeserializer &deserializer) {
56 auto child = deserializer.ReadProperty<unique_ptr<ParsedExpression>>(tag: "child");
57 auto collation = deserializer.ReadProperty<string>(tag: "collation");
58 return make_uniq_base<ParsedExpression, CollateExpression>(args&: collation, args: std::move(child));
59}
60
61} // namespace duckdb
62