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::MultiFileOptions Struct Reference

Public Member Functions

DUCKDB_API void Serialize (Serializer &serializer) const
DUCKDB_API void AddBatchInfo (BindInfo &bind_info) const
DUCKDB_API void AutoDetectHivePartitioning (MultiFileList &files, ClientContext &context)
DUCKDB_API void AutoDetectHiveTypesInternal (MultiFileList &files, ClientContext &context)
DUCKDB_API void VerifyHiveTypesArePartitions (const std::map< string, string > &partitions) const
DUCKDB_API LogicalType GetHiveLogicalType (const string &hive_partition_column) const
DUCKDB_API Value GetHivePartitionValue (const string &base, const string &entry, ClientContext &context) const
DUCKDB_API bool AnySet () const

Static Public Member Functions

static DUCKDB_API MultiFileOptions Deserialize (Deserializer &source)
static DUCKDB_API bool AutoDetectHivePartitioningInternal (MultiFileList &files, ClientContext &context)

Public Attributes

bool filename = false
bool hive_partitioning = false
bool auto_detect_hive_partitioning = true
bool union_by_name = false
bool hive_types_autocast = true
MultiFileColumnMappingMode mapping = MultiFileColumnMappingMode::BY_NAME
case_insensitive_map_t< LogicalType > hive_types_schema
string filename_column = DEFAULT_FILENAME_COLUMN
case_insensitive_map_t< Value > custom_options

Static Public Attributes

static constexpr const char * DEFAULT_FILENAME_COLUMN = "filename"

Member Function Documentation

◆ Serialize()

void duckdb::MultiFileOptions::Serialize ( Serializer & serializer) const
417532 {
417533 serializer.WritePropertyWithDefault<bool>(100, "filename", filename);
417534 serializer.WritePropertyWithDefault<bool>(101, "hive_partitioning", hive_partitioning);
417535 serializer.WritePropertyWithDefault<bool>(102, "auto_detect_hive_partitioning", auto_detect_hive_partitioning);
417536 serializer.WritePropertyWithDefault<bool>(103, "union_by_name", union_by_name);
417537 serializer.WritePropertyWithDefault<bool>(104, "hive_types_autocast", hive_types_autocast);
417538 serializer.WritePropertyWithDefault<case_insensitive_map_t<LogicalType>>(105, "hive_types_schema", hive_types_schema);
417539 serializer.WritePropertyWithDefault<string>(106, "filename_column", filename_column, MultiFileOptions::DEFAULT_FILENAME_COLUMN);
417540}

◆ Deserialize()

MultiFileOptions duckdb::MultiFileOptions::Deserialize ( Deserializer & source)
static
417542 {
417543 MultiFileOptions result;
417544 deserializer.ReadPropertyWithDefault<bool>(100, "filename", result.filename);
417545 deserializer.ReadPropertyWithDefault<bool>(101, "hive_partitioning", result.hive_partitioning);
417546 deserializer.ReadPropertyWithDefault<bool>(102, "auto_detect_hive_partitioning", result.auto_detect_hive_partitioning);
417547 deserializer.ReadPropertyWithDefault<bool>(103, "union_by_name", result.union_by_name);
417548 deserializer.ReadPropertyWithDefault<bool>(104, "hive_types_autocast", result.hive_types_autocast);
417549 deserializer.ReadPropertyWithDefault<case_insensitive_map_t<LogicalType>>(105, "hive_types_schema", result.hive_types_schema);
417550 deserializer.ReadPropertyWithExplicitDefault<string>(106, "filename_column", result.filename_column, MultiFileOptions::DEFAULT_FILENAME_COLUMN);
417551 return result;
417552}

◆ AddBatchInfo()

void duckdb::MultiFileOptions::AddBatchInfo ( BindInfo & bind_info) const
84876 {
84877 bind_info.InsertOption("filename", Value(filename_column));
84878 bind_info.InsertOption("hive_partitioning", Value::BOOLEAN(hive_partitioning));
84879 bind_info.InsertOption("auto_detect_hive_partitioning", Value::BOOLEAN(auto_detect_hive_partitioning));
84880 bind_info.InsertOption("union_by_name", Value::BOOLEAN(union_by_name));
84881 bind_info.InsertOption("hive_types_autocast", Value::BOOLEAN(hive_types_autocast));
84882}
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118

◆ AutoDetectHivePartitioning()

void duckdb::MultiFileOptions::AutoDetectHivePartitioning ( MultiFileList & files,
ClientContext & context )
84974 {
84975 if (files.GetExpandResult() == FileExpandResult::NO_FILES) {
84976 return;
84977 }
84978 const bool hp_explicitly_disabled = !auto_detect_hive_partitioning && !hive_partitioning;
84979 const bool ht_enabled = !hive_types_schema.empty();
84980 if (hp_explicitly_disabled && ht_enabled) {
84981 throw InvalidInputException("cannot disable hive_partitioning when hive_types is enabled");
84982 }
84983 if (ht_enabled && auto_detect_hive_partitioning && !hive_partitioning) {
84984 // hive_types flag implies hive_partitioning
84985 hive_partitioning = true;
84986 auto_detect_hive_partitioning = false;
84987 }
84988 if (auto_detect_hive_partitioning) {
84989 hive_partitioning = AutoDetectHivePartitioningInternal(files, context);
84990 }
84991 if (hive_partitioning && hive_types_autocast) {
84992 AutoDetectHiveTypesInternal(files, context);
84993 }
84994}

◆ AutoDetectHivePartitioningInternal()

bool duckdb::MultiFileOptions::AutoDetectHivePartitioningInternal ( MultiFileList & files,
ClientContext & context )
static
84905 {
84906 auto first_file = files.GetFirstFile();
84907 auto partitions = HivePartitioning::Parse(first_file.path);
84908 if (partitions.empty()) {
84909 // no partitions found in first file
84910 return false;
84911 }
84912
84913 for (const auto &file : files.Files()) {
84914 auto new_partitions = HivePartitioning::Parse(file.path);
84915 if (new_partitions.size() != partitions.size()) {
84916 // partition count mismatch
84917 return false;
84918 }
84919 for (auto &part : new_partitions) {
84920 auto entry = partitions.find(part.first);
84921 if (entry == partitions.end()) {
84922 // differing partitions between files
84923 return false;
84924 }
84925 }
84926 }
84927 return true;
84928}
static DUCKDB_API std::map< string, string > Parse(const string &filename)
Parse a filename that follows the hive partitioning scheme.
Definition duckdb.cpp:77861

◆ AutoDetectHiveTypesInternal()

void duckdb::MultiFileOptions::AutoDetectHiveTypesInternal ( MultiFileList & files,
ClientContext & context )
84929 {
84930 const LogicalType candidates[] = {LogicalType::DATE, LogicalType::TIMESTAMP, LogicalType::BIGINT};
84931
84932 unordered_map<string, LogicalType> detected_types;
84933 for (const auto &file : files.Files()) {
84934 auto partitions = HivePartitioning::Parse(file.path);
84935 if (partitions.empty()) {
84936 return;
84937 }
84938
84939 for (auto &part : partitions) {
84940 const string &name = part.first;
84941 if (hive_types_schema.find(name) != hive_types_schema.end()) {
84942 // type was explicitly provided by the user
84943 continue;
84944 }
84945 if (HivePartitioning::IsNull(part.second)) {
84946 continue; // don't update detected_types for this partition/file
84947 }
84948 LogicalType detected_type = LogicalType::VARCHAR;
84949 Value value(part.second);
84950 for (auto &candidate : candidates) {
84951 const bool success = value.TryCastAs(context, candidate, true);
84952 if (success) {
84953 detected_type = candidate;
84954 break;
84955 }
84956 }
84957 auto entry = detected_types.find(name);
84958 if (entry == detected_types.end()) {
84959 // type was not yet detected - insert it
84960 detected_types.insert(make_pair(name, std::move(detected_type)));
84961 } else {
84962 // type was already detected - check if the type matches
84963 // if not promote to VARCHAR
84964 if (entry->second != detected_type) {
84965 entry->second = LogicalType::VARCHAR;
84966 }
84967 }
84968 }
84969 }
84970 for (auto &entry : detected_types) {
84971 hive_types_schema.insert(make_pair(entry.first, std::move(entry.second)));
84972 }
84973}
static DUCKDB_API bool IsNull(const string &input)
Whether the column is "NULL"/"__HIVE_DEFAULT_PARTITION".
Definition duckdb.cpp:77853

◆ VerifyHiveTypesArePartitions()

void duckdb::MultiFileOptions::VerifyHiveTypesArePartitions ( const std::map< string, string > & partitions) const
84995 {
84996 for (auto &hive_type : hive_types_schema) {
84997 if (partitions.find(hive_type.first) == partitions.end()) {
84998 throw InvalidInputException("Unknown hive_type: \"%s\" does not appear to be a partition", hive_type.first);
84999 }
85000 }
85001}

◆ GetHiveLogicalType()

LogicalType duckdb::MultiFileOptions::GetHiveLogicalType ( const string & hive_partition_column) const
85002 {
85003 if (!hive_types_schema.empty()) {
85004 auto it = hive_types_schema.find(hive_partition_column);
85005 if (it != hive_types_schema.end()) {
85006 return it->second;
85007 }
85008 }
85009 return LogicalType::VARCHAR;
85010}

◆ GetHivePartitionValue()

Value duckdb::MultiFileOptions::GetHivePartitionValue ( const string & base,
const string & entry,
ClientContext & context ) const
85016 {
85017 auto it = hive_types_schema.find(key);
85018 if (it == hive_types_schema.end()) {
85019 return HivePartitioning::GetValue(context, key, value, LogicalType::VARCHAR);
85020 }
85021 return HivePartitioning::GetValue(context, key, value, it->second);
85022}

◆ AnySet()

bool duckdb::MultiFileOptions::AnySet ( ) const
85012 {
85013 return filename || hive_partitioning || union_by_name;
85014}

The documentation for this struct was generated from the following files: