1#include "duckdb/parser/expression/parameter_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/to_string.hpp"
7
8#include "duckdb/common/serializer/format_serializer.hpp"
9#include "duckdb/common/serializer/format_deserializer.hpp"
10
11namespace duckdb {
12
13ParameterExpression::ParameterExpression()
14 : ParsedExpression(ExpressionType::VALUE_PARAMETER, ExpressionClass::PARAMETER), parameter_nr(0) {
15}
16
17string ParameterExpression::ToString() const {
18 return "$" + to_string(val: parameter_nr);
19}
20
21unique_ptr<ParsedExpression> ParameterExpression::Copy() const {
22 auto copy = make_uniq<ParameterExpression>();
23 copy->parameter_nr = parameter_nr;
24 copy->CopyProperties(other: *this);
25 return std::move(copy);
26}
27
28bool ParameterExpression::Equal(const ParameterExpression &a, const ParameterExpression &b) {
29 return a.parameter_nr == b.parameter_nr;
30}
31
32hash_t ParameterExpression::Hash() const {
33 hash_t result = ParsedExpression::Hash();
34 return CombineHash(left: duckdb::Hash(val: parameter_nr), right: result);
35}
36
37void ParameterExpression::Serialize(FieldWriter &writer) const {
38 writer.WriteField<idx_t>(element: parameter_nr);
39}
40
41unique_ptr<ParsedExpression> ParameterExpression::Deserialize(ExpressionType type, FieldReader &reader) {
42 auto expression = make_uniq<ParameterExpression>();
43 expression->parameter_nr = reader.ReadRequired<idx_t>();
44 return std::move(expression);
45}
46
47void ParameterExpression::FormatSerialize(FormatSerializer &serializer) const {
48 ParsedExpression::FormatSerialize(serializer);
49 serializer.WriteProperty(tag: "parameter_nr", value: parameter_nr);
50}
51
52unique_ptr<ParsedExpression> ParameterExpression::FormatDeserialize(ExpressionType type,
53 FormatDeserializer &deserializer) {
54 auto expression = make_uniq<ParameterExpression>();
55 expression->parameter_nr = deserializer.ReadProperty<idx_t>(tag: "parameter_nr");
56 return std::move(expression);
57}
58
59} // namespace duckdb
60