Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::FunctionSerializer Class Reference

Static Public Member Functions

template<class FUNC>
static void Serialize (Serializer &serializer, const FUNC &function, optional_ptr< FunctionData > bind_info)
template<class FUNC, class CATALOG_ENTRY>
static FUNC DeserializeFunction (ClientContext &context, CatalogType catalog_type, const string &catalog_name, const string &schema_name, const string &name, const vector< LogicalType > &arguments, const vector< LogicalType > &original_arguments)
template<class FUNC, class CATALOG_ENTRY>
static pair< FUNC, bool > DeserializeBase (Deserializer &deserializer, CatalogType catalog_type, optional_ptr< vector< unique_ptr< Expression > > > children=nullptr)
template<class FUNC>
static unique_ptr< FunctionData > FunctionDeserialize (Deserializer &deserializer, FUNC &function)
static bool TypeRequiresAssignment (const LogicalType &type)
template<class FUNC, class CATALOG_ENTRY>
static pair< FUNC, unique_ptr< FunctionData > > Deserialize (Deserializer &deserializer, CatalogType catalog_type, vector< unique_ptr< Expression > > &children, LogicalType return_type)

Member Function Documentation

◆ Serialize()

template<class FUNC>
void duckdb::FunctionSerializer::Serialize ( Serializer & serializer,
const FUNC & function,
optional_ptr< FunctionData > bind_info )
inlinestatic
375388 {
375389 D_ASSERT(!function.name.empty());
375390 serializer.WriteProperty(500, "name", function.name);
375391 serializer.WriteProperty(501, "arguments", function.arguments);
375392 serializer.WriteProperty(502, "original_arguments", function.original_arguments);
375393 // These are optional fields that are written out of numeric order, older
375394 // databases won't contain the fields, so the defaults will be used, but if
375395 // the fields are present, they will be used.
375396 serializer.WritePropertyWithDefault<string>(505, "catalog_name", function.catalog_name, "");
375397 serializer.WritePropertyWithDefault<string>(506, "schema_name", function.schema_name, "");
375398
375399 bool has_serialize = function.HasSerializationCallbacks();
375400 serializer.WriteProperty(503, "has_serialize", has_serialize);
375401 if (has_serialize) {
375402 serializer.WriteObject(504, "function_data",
375403 [&](Serializer &obj) { function.GetSerializeCallback()(obj, bind_info, function); });
375404 D_ASSERT(function.GetDeserializeCallback());
375405 }
375406 }

◆ DeserializeFunction()

template<class FUNC, class CATALOG_ENTRY>
FUNC duckdb::FunctionSerializer::DeserializeFunction ( ClientContext & context,
CatalogType catalog_type,
const string & catalog_name,
const string & schema_name,
const string & name,
const vector< LogicalType > & arguments,
const vector< LogicalType > & original_arguments )
inlinestatic
375411 {
375412 EntryLookupInfo lookup_info(catalog_type, name);
375413 auto &func_catalog =
375414 Catalog::GetEntry(context, catalog_type, catalog_name.empty() ? SYSTEM_CATALOG : catalog_name,
375415 schema_name.empty() ? DEFAULT_SCHEMA : schema_name, name);
375416
375417 if (func_catalog.type != catalog_type) {
375418 throw InternalException("DeserializeFunction - cant find catalog entry for function %s", name);
375419 }
375420 auto &functions = func_catalog.Cast<CATALOG_ENTRY>();
375421 auto function = functions.functions.GetFunctionByArguments(
375422 context, original_arguments.empty() ? arguments : original_arguments);
375423 return function;
375424 }
DUCKDB_API optional_ptr< CatalogEntry > GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found)
Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEnt...
Definition duckdb.cpp:8156

◆ DeserializeBase()

template<class FUNC, class CATALOG_ENTRY>
pair< FUNC, bool > duckdb::FunctionSerializer::DeserializeBase ( Deserializer & deserializer,
CatalogType catalog_type,
optional_ptr< vector< unique_ptr< Expression > > > children = nullptr )
inlinestatic
375428 {
375429 auto &context = deserializer.Get<ClientContext &>();
375430 auto name = deserializer.ReadProperty<string>(500, "name");
375431 auto arguments = deserializer.ReadProperty<vector<LogicalType>>(501, "arguments");
375432 auto original_arguments = deserializer.ReadProperty<vector<LogicalType>>(502, "original_arguments");
375433 auto catalog_name = deserializer.ReadPropertyWithDefault<string>(505, "catalog_name");
375434 auto schema_name = deserializer.ReadPropertyWithDefault<string>(506, "schema_name");
375435 if (catalog_name.empty()) {
375436 catalog_name = SYSTEM_CATALOG;
375437 }
375438 if (schema_name.empty()) {
375439 schema_name = DEFAULT_SCHEMA;
375440 }
375441
375442 if (arguments.empty() && original_arguments.empty() && children && !children->empty()) {
375443 // The function is specified as having no arguments, but somehow expressions were passed anyway
375444 // Assume this is a "varargs" function and use the types of the expressions as the arguments
375445 // This can happen when we change a function that used to take varargs, to no longer do so.
375446 arguments.reserve(children->size());
375447 for (auto &child : *children) {
375448 arguments.push_back(child->return_type);
375449 }
375450 }
375451
375452 auto function = DeserializeFunction<FUNC, CATALOG_ENTRY>(context, catalog_type, catalog_name, schema_name, name,
375453 arguments, original_arguments);
375454 auto has_serialize = deserializer.ReadProperty<bool>(503, "has_serialize");
375455 if (has_serialize) {
375456 function.arguments = std::move(arguments);
375457 function.original_arguments = std::move(original_arguments);
375458 }
375459 return make_pair(std::move(function), has_serialize);
375460 }

◆ FunctionDeserialize()

template<class FUNC>
unique_ptr< FunctionData > duckdb::FunctionSerializer::FunctionDeserialize ( Deserializer & deserializer,
FUNC & function )
inlinestatic
375463 {
375464 if (!function.HasSerializationCallbacks()) {
375465 throw SerializationException("Function requires deserialization but no deserialization function for %s",
375466 function.name);
375467 }
375468 unique_ptr<FunctionData> result;
375469 deserializer.ReadObject(504, "function_data",
375470 [&](Deserializer &obj) { result = function.GetDeserializeCallback()(obj, function); });
375471 return result;
375472 }

◆ TypeRequiresAssignment()

bool duckdb::FunctionSerializer::TypeRequiresAssignment ( const LogicalType & type)
inlinestatic
375474 {
375475 switch (type.id()) {
375476 case LogicalTypeId::SQLNULL:
375477 case LogicalTypeId::ANY:
375478 case LogicalTypeId::INVALID:
375479 return true;
375480 case LogicalTypeId::DECIMAL:
375481 case LogicalTypeId::UNION:
375482 case LogicalTypeId::VARIANT:
375483 case LogicalTypeId::MAP:
375484 if (!type.AuxInfo()) {
375485 return true;
375486 }
375487 return false;
375488 case LogicalTypeId::LIST:
375489 if (!type.AuxInfo()) {
375490 return true;
375491 }
375492 return TypeRequiresAssignment(ListType::GetChildType(type));
375493 case LogicalTypeId::ARRAY:
375494 if (!type.AuxInfo()) {
375495 return true;
375496 }
375497 return TypeRequiresAssignment(ArrayType::GetChildType(type));
375498 case LogicalTypeId::STRUCT:
375499 if (!type.AuxInfo()) {
375500 return true;
375501 }
375502 if (StructType::GetChildCount(type) == 0) {
375503 return true;
375504 }
375505 return false;
375506 default:
375507 return false;
375508 }
375509 }

◆ Deserialize()

template<class FUNC, class CATALOG_ENTRY>
pair< FUNC, unique_ptr< FunctionData > > duckdb::FunctionSerializer::Deserialize ( Deserializer & deserializer,
CatalogType catalog_type,
vector< unique_ptr< Expression > > & children,
LogicalType return_type )
inlinestatic
375514 { // NOLINT: clang-tidy bug
375515 auto &context = deserializer.Get<ClientContext &>();
375516 auto entry = DeserializeBase<FUNC, CATALOG_ENTRY>(deserializer, catalog_type, children);
375517 auto &function = entry.first;
375518 auto has_serialize = entry.second;
375519
375520 unique_ptr<FunctionData> bind_data;
375521 if (has_serialize) {
375522 deserializer.Set<const LogicalType &>(return_type);
375523 bind_data = FunctionDeserialize<FUNC>(deserializer, function);
375524 deserializer.Unset<LogicalType>();
375525 } else {
375526 FunctionBinder binder(context);
375527
375528 // Resolve templates
375529 binder.ResolveTemplateTypes(function, children);
375530
375531 if (function.HasBindCallback()) {
375532 try {
375533 bind_data = function.GetBindCallback()(context, function, children);
375534 } catch (std::exception &ex) {
375535 ErrorData error(ex);
375536 throw SerializationException("Error during bind of function in deserialization: %s",
375537 error.RawMessage());
375538 }
375539 }
375540
375541 // Verify that all templates are bound to concrete types.
375542 binder.CheckTemplateTypesResolved(function);
375543
375544 binder.CastToFunctionArguments(function, children);
375545 }
375546
375547 if (TypeRequiresAssignment(function.GetReturnType())) {
375548 function.SetReturnType(std::move(return_type));
375549 }
375550 return make_pair(std::move(function), std::move(bind_data));
375551 }

The documentation for this class was generated from the following file: