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::ArrowSchemaMetadata Class Reference
Collaboration diagram for duckdb::ArrowSchemaMetadata:

Public Member Functions

 ArrowSchemaMetadata (const char *metadata)
 Constructor used to read a metadata schema, used when importing an arrow object.
 
 ArrowSchemaMetadata ()
 Constructor used to create a metadata schema, used when exporting an arrow object.
 
void AddOption (const string &key, const string &value)
 Adds an option to the metadata.
 
string GetOption (const string &key) const
 Gets an option from the metadata, returns an empty string if it does not exist.
 
unsafe_unique_array< charSerializeMetadata () const
 Transforms metadata to a char*, used when creating an arrow object.
 
bool HasExtension () const
 If the arrow extension is set.
 
ArrowExtensionMetadata GetExtensionInfo (string format)
 
string GetExtensionName () const
 Get the extension name if set, otherwise returns empty.
 

Static Public Member Functions

static ArrowSchemaMetadata ArrowCanonicalType (const string &extension_name)
 Creates the metadata based on an extension name.
 
static ArrowSchemaMetadata NonCanonicalType (const string &type_name, const string &vendor_name)
 Creates the metadata based on an extension name.
 

Static Public Attributes

static constexpr const charARROW_EXTENSION_NAME = "ARROW:extension:name"
 Key for encode of the extension type name.
 
static constexpr const charARROW_METADATA_KEY = "ARROW:extension:metadata"
 Key for encode of the metadata key.
 

Private Attributes

unordered_map< string, string > schema_metadata_map
 The unordered map that holds the metadata.
 
unique_ptr< ComplexJSONextension_metadata_map
 The extension metadata map, currently only used for internal types in arrow.opaque.
 

Constructor & Destructor Documentation

◆ ArrowSchemaMetadata() [1/2]

duckdb::ArrowSchemaMetadata::ArrowSchemaMetadata ( const char metadata)
explicit

Constructor used to read a metadata schema, used when importing an arrow object.

46264 {
46265 if (metadata) {
46266 // Read the number of key-value pairs (int32)
46267 int32_t num_pairs;
46268 memcpy(&num_pairs, metadata, sizeof(int32_t));
46269 metadata += sizeof(int32_t);
46270
46271 // Loop through each key-value pair
46272 for (int32_t i = 0; i < num_pairs; ++i) {
46273 // Read the length of the key (int32)
46274 int32_t key_length;
46275 memcpy(&key_length, metadata, sizeof(int32_t));
46276 metadata += sizeof(int32_t);
46277
46278 // Read the key
46279 std::string key(metadata, static_cast<idx_t>(key_length));
46280 metadata += key_length;
46281
46282 // Read the length of the value (int32)
46283 int32_t value_length;
46284 memcpy(&value_length, metadata, sizeof(int32_t));
46285 metadata += sizeof(int32_t);
46286
46287 // Read the value
46288 const std::string value(metadata, static_cast<idx_t>(value_length));
46289 metadata += value_length;
46290 schema_metadata_map[key] = value;
46291 }
46292 }
46293 // We ignore errors of the metadata parsing if the extension is different from arrow.opaque
46294 const bool ignore_errors =
46297}
static constexpr const char * ARROW_EXTENSION_NAME
Key for encode of the extension type name.
Definition duckdb.cpp:34556
static constexpr const char * ARROW_METADATA_KEY
Key for encode of the metadata key.
Definition duckdb.cpp:34558
unordered_map< string, string > schema_metadata_map
The unordered map that holds the metadata.
Definition duckdb.cpp:34566
unique_ptr< ComplexJSON > extension_metadata_map
The extension metadata map, currently only used for internal types in arrow.opaque.
Definition duckdb.cpp:34568
static DUCKDB_API unique_ptr< ComplexJSON > ParseJSONMap(const string &json, bool ignore_errors=false)
::int32_t int32_t
static constexpr const char * ARROW_EXTENSION_NON_CANONICAL
Arrow Extension for non-canonical types.
Definition duckdb.hpp:37795
Here is the call graph for this function:

◆ ArrowSchemaMetadata() [2/2]

duckdb::ArrowSchemaMetadata::ArrowSchemaMetadata ( )

Constructor used to create a metadata schema, used when exporting an arrow object.

46299 {
46300 // Always initialize out metadata map
46301 extension_metadata_map = make_uniq<ComplexJSON>();
46302}

Member Function Documentation

◆ AddOption()

void duckdb::ArrowSchemaMetadata::AddOption ( const string &  key,
const string &  value 
)

Adds an option to the metadata.

46304 {
46305 schema_metadata_map[key] = value;
46306}
Here is the caller graph for this function:

◆ GetOption()

string duckdb::ArrowSchemaMetadata::GetOption ( const string &  key) const

Gets an option from the metadata, returns an empty string if it does not exist.

46308 {
46309 auto it = schema_metadata_map.find(key);
46310 if (it != schema_metadata_map.end()) {
46311 return it->second;
46312 } else {
46313 return "";
46314 }
46315}
Here is the caller graph for this function:

◆ SerializeMetadata()

unsafe_unique_array< char > duckdb::ArrowSchemaMetadata::SerializeMetadata ( ) const

Transforms metadata to a char*, used when creating an arrow object.

46344 {
46345 // First we have to figure out the total size:
46346 // 1. number of key-value pairs (int32)
46347 idx_t total_size = sizeof(int32_t);
46348 for (const auto &option : schema_metadata_map) {
46349 // 2. Length of the key and value (2 * int32)
46350 total_size += 2 * sizeof(int32_t);
46351 // 3. Length of key
46352 total_size += option.first.size();
46353 // 4. Length of value
46354 total_size += option.second.size();
46355 }
46356 auto metadata_array_ptr = make_unsafe_uniq_array<char>(total_size);
46357 auto metadata_ptr = metadata_array_ptr.get();
46358 // 1. number of key-value pairs (int32)
46359 const int32_t map_size = static_cast<int32_t>(schema_metadata_map.size());
46360 memcpy(metadata_ptr, &map_size, sizeof(int32_t));
46361 metadata_ptr += sizeof(int32_t);
46362 // Iterate through each key-value pair in the map
46363 for (const auto &pair : schema_metadata_map) {
46364 const std::string &key = pair.first;
46365 int32_t key_size = static_cast<int32_t>(key.size());
46366 // Length of the key (int32)
46367 memcpy(metadata_ptr, &key_size, sizeof(int32_t));
46368 metadata_ptr += sizeof(int32_t);
46369 // Key
46370 memcpy(metadata_ptr, key.c_str(), key.size());
46371 metadata_ptr += key_size;
46372 const std::string &value = pair.second;
46373 const int32_t value_size = static_cast<int32_t>(value.size());
46374 // Length of the value (int32)
46375 memcpy(metadata_ptr, &value_size, sizeof(int32_t));
46376 metadata_ptr += sizeof(int32_t);
46377 // Value
46378 memcpy(metadata_ptr, value.c_str(), value.size());
46379 metadata_ptr += value_size;
46380 }
46381 return metadata_array_ptr;
46382}

◆ HasExtension()

bool duckdb::ArrowSchemaMetadata::HasExtension ( ) const

If the arrow extension is set.

46334 {
46336 return !arrow_extension.empty();
46337}
string GetOption(const string &key) const
Gets an option from the metadata, returns an empty string if it does not exist.
Definition duckdb.cpp:46308
Here is the call graph for this function:

◆ GetExtensionInfo()

ArrowExtensionMetadata duckdb::ArrowSchemaMetadata::GetExtensionInfo ( string  format)
46339 {
46340 return {schema_metadata_map[ARROW_EXTENSION_NAME], extension_metadata_map->GetValue("vendor_name"),
46341 extension_metadata_map->GetValue("type_name"), std::move(format)};
46342}

◆ ArrowCanonicalType()

ArrowSchemaMetadata duckdb::ArrowSchemaMetadata::ArrowCanonicalType ( const string &  extension_name)
static

Creates the metadata based on an extension name.

46317 {
46318 ArrowSchemaMetadata metadata;
46319 metadata.AddOption(ARROW_EXTENSION_NAME, extension_name);
46320 metadata.AddOption(ARROW_METADATA_KEY, "");
46321 return metadata;
46322}
ArrowSchemaMetadata()
Constructor used to create a metadata schema, used when exporting an arrow object.
Definition duckdb.cpp:46299
Here is the call graph for this function:

◆ NonCanonicalType()

ArrowSchemaMetadata duckdb::ArrowSchemaMetadata::NonCanonicalType ( const string &  type_name,
const string &  vendor_name 
)
static

Creates the metadata based on an extension name.

46324 {
46325 ArrowSchemaMetadata metadata;
46327 // We have to set the metadata key with type_name and vendor_name.
46328 metadata.extension_metadata_map->AddObjectEntry("vendor_name", make_uniq<ComplexJSON>(vendor_name));
46329 metadata.extension_metadata_map->AddObjectEntry("type_name", make_uniq<ComplexJSON>(type_name));
46330 metadata.AddOption(ARROW_METADATA_KEY, StringUtil::ToComplexJSONMap(*metadata.extension_metadata_map));
46331 return metadata;
46332}
static DUCKDB_API string ToComplexJSONMap(const ComplexJSON &complex_json)
Transforms an complex JSON to a JSON string.
Here is the call graph for this function:

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