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