1#include "duckdb/parser/parsed_data/alter_info.hpp"
2#include "duckdb/parser/parsed_data/alter_table_info.hpp"
3#include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"
4#include "duckdb/parser/parsed_data/alter_table_function_info.hpp"
5
6#include "duckdb/common/field_writer.hpp"
7
8namespace duckdb {
9
10AlterInfo::AlterInfo(AlterType type, string catalog_p, string schema_p, string name_p, OnEntryNotFound if_not_found)
11 : type(type), if_not_found(if_not_found), catalog(std::move(catalog_p)), schema(std::move(schema_p)),
12 name(std::move(name_p)), allow_internal(false) {
13}
14
15AlterInfo::~AlterInfo() {
16}
17
18void AlterInfo::Serialize(Serializer &serializer) const {
19 FieldWriter writer(serializer);
20 writer.WriteField<AlterType>(element: type);
21 Serialize(writer);
22 writer.Finalize();
23}
24
25unique_ptr<AlterInfo> AlterInfo::Deserialize(Deserializer &source) {
26 FieldReader reader(source);
27 auto type = reader.ReadRequired<AlterType>();
28
29 unique_ptr<AlterInfo> result;
30 switch (type) {
31 case AlterType::ALTER_TABLE:
32 result = AlterTableInfo::Deserialize(reader);
33 break;
34 case AlterType::ALTER_VIEW:
35 result = AlterViewInfo::Deserialize(reader);
36 break;
37 case AlterType::ALTER_SCALAR_FUNCTION:
38 result = AlterScalarFunctionInfo::Deserialize(reader);
39 break;
40 case AlterType::ALTER_TABLE_FUNCTION:
41 result = AlterTableFunctionInfo::Deserialize(reader);
42 break;
43 default:
44 throw SerializationException("Unknown alter type for deserialization!");
45 }
46 reader.Finalize();
47
48 return result;
49}
50
51AlterEntryData AlterInfo::GetAlterEntryData() const {
52 AlterEntryData data;
53 data.catalog = catalog;
54 data.schema = schema;
55 data.name = name;
56 data.if_not_found = if_not_found;
57 return data;
58}
59
60} // namespace duckdb
61