1#include "duckdb/planner/operator/logical_create_index.hpp"
2
3#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
4#include "duckdb/parser/parsed_data/create_table_info.hpp"
5#include "duckdb/function/function_serialization.hpp"
6
7namespace duckdb {
8
9void LogicalCreateIndex::Serialize(FieldWriter &writer) const {
10 writer.WriteOptional(element: info);
11 writer.WriteString(val: table.catalog.GetName());
12 writer.WriteString(val: table.schema.name);
13 writer.WriteString(val: table.name);
14 FunctionSerializer::SerializeBase<TableFunction>(writer, function, bind_info: bind_data.get());
15 writer.WriteSerializableList(elements: unbound_expressions);
16}
17
18unique_ptr<LogicalOperator> LogicalCreateIndex::Deserialize(LogicalDeserializationState &state, FieldReader &reader) {
19 auto &context = state.gstate.context;
20
21 auto info = reader.ReadOptional<CreateInfo>(default_value: nullptr);
22 auto catalog = reader.ReadRequired<string>();
23 auto schema = reader.ReadRequired<string>();
24 auto table_name = reader.ReadRequired<string>();
25 unique_ptr<FunctionData> bind_data;
26 bool has_deserialize;
27 auto function = FunctionSerializer::DeserializeBaseInternal<TableFunction, TableFunctionCatalogEntry>(
28 reader, state&: state.gstate, type: CatalogType::TABLE_FUNCTION_ENTRY, bind_info&: bind_data, has_deserialize);
29 auto unbound_expressions = reader.ReadRequiredSerializableList<Expression>(args&: state.gstate);
30 if (info->type != CatalogType::INDEX_ENTRY) {
31 throw InternalException("Unexpected type: '%s', expected '%s'", CatalogTypeToString(type: info->type),
32 CatalogTypeToString(type: CatalogType::INDEX_ENTRY));
33 }
34 auto index_info = unique_ptr_cast<CreateInfo, CreateIndexInfo>(src: std::move(info));
35 auto &table = Catalog::GetEntry<TableCatalogEntry>(context, catalog_name: catalog, schema_name: schema, name: table_name);
36 return make_uniq<LogicalCreateIndex>(args: std::move(bind_data), args: std::move(index_info), args: std::move(unbound_expressions),
37 args&: table, args: std::move(function));
38}
39
40} // namespace duckdb
41