1#include "duckdb/parser/expression/constant_expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/field_writer.hpp"
5#include "duckdb/common/types/hash.hpp"
6#include "duckdb/common/value_operations/value_operations.hpp"
7
8#include "duckdb/common/serializer/format_serializer.hpp"
9#include "duckdb/common/serializer/format_deserializer.hpp"
10
11namespace duckdb {
12
13ConstantExpression::ConstantExpression(Value val)
14 : ParsedExpression(ExpressionType::VALUE_CONSTANT, ExpressionClass::CONSTANT), value(std::move(val)) {
15}
16
17string ConstantExpression::ToString() const {
18 return value.ToSQLString();
19}
20
21bool ConstantExpression::Equal(const ConstantExpression &a, const ConstantExpression &b) {
22 return a.value.type() == b.value.type() && !ValueOperations::DistinctFrom(left: a.value, right: b.value);
23}
24
25hash_t ConstantExpression::Hash() const {
26 return value.Hash();
27}
28
29unique_ptr<ParsedExpression> ConstantExpression::Copy() const {
30 auto copy = make_uniq<ConstantExpression>(args: value);
31 copy->CopyProperties(other: *this);
32 return std::move(copy);
33}
34
35void ConstantExpression::Serialize(FieldWriter &writer) const {
36 writer.WriteSerializable(element: value);
37}
38
39unique_ptr<ParsedExpression> ConstantExpression::Deserialize(ExpressionType type, FieldReader &reader) {
40 Value value = reader.ReadRequiredSerializable<Value, Value>();
41 return make_uniq<ConstantExpression>(args: std::move(value));
42}
43
44void ConstantExpression::FormatSerialize(FormatSerializer &serializer) const {
45 ParsedExpression::FormatSerialize(serializer);
46 serializer.WriteProperty(tag: "value", value);
47}
48
49unique_ptr<ParsedExpression> ConstantExpression::FormatDeserialize(ExpressionType type,
50 FormatDeserializer &deserializer) {
51 auto value = deserializer.ReadProperty<Value>(tag: "value");
52 return make_uniq<ConstantExpression>(args: std::move(value));
53}
54
55} // namespace duckdb
56