1#include "duckdb/planner/expression/bound_constant_expression.hpp"
2#include "duckdb/common/field_writer.hpp"
3#include "duckdb/common/types/hash.hpp"
4#include "duckdb/common/value_operations/value_operations.hpp"
5
6namespace duckdb {
7
8BoundConstantExpression::BoundConstantExpression(Value value_p)
9 : Expression(ExpressionType::VALUE_CONSTANT, ExpressionClass::BOUND_CONSTANT, value_p.type()),
10 value(std::move(value_p)) {
11}
12
13string BoundConstantExpression::ToString() const {
14 return value.ToSQLString();
15}
16
17bool BoundConstantExpression::Equals(const BaseExpression &other_p) const {
18 if (!Expression::Equals(other: other_p)) {
19 return false;
20 }
21 auto &other = other_p.Cast<BoundConstantExpression>();
22 return value.type() == other.value.type() && !ValueOperations::DistinctFrom(left: value, right: other.value);
23}
24
25hash_t BoundConstantExpression::Hash() const {
26 hash_t result = Expression::Hash();
27 return CombineHash(left: value.Hash(), right: result);
28}
29
30unique_ptr<Expression> BoundConstantExpression::Copy() {
31 auto copy = make_uniq<BoundConstantExpression>(args&: value);
32 copy->CopyProperties(other&: *this);
33 return std::move(copy);
34}
35
36void BoundConstantExpression::Serialize(FieldWriter &writer) const {
37 value.Serialize(serializer&: writer.GetSerializer());
38}
39
40unique_ptr<Expression> BoundConstantExpression::Deserialize(ExpressionDeserializationState &state,
41 FieldReader &reader) {
42 auto value = Value::Deserialize(source&: reader.GetSource());
43 return make_uniq<BoundConstantExpression>(args&: value);
44}
45
46} // namespace duckdb
47