176799 {
176801
176802 if (StoreUserDefinedParameter(loption)) {
176804 }
176805 if (loption == "columns") {
176807 throw BinderException("read_csv column_names/names can only be supplied once");
176808 }
176810 auto &child_type = val.type();
176811 if (child_type.id() != LogicalTypeId::STRUCT) {
176812 throw BinderException("read_csv columns requires a struct as input");
176813 }
176814 auto &struct_children = StructValue::GetChildren(val);
176815 D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size());
176816 for (
idx_t i = 0; i < struct_children.size(); i++) {
176817 auto &name = StructType::GetChildName(child_type, i);
176818 auto &val = struct_children[i];
176820 if (val.type().id() != LogicalTypeId::VARCHAR) {
176821 throw BinderException("read_csv requires a type specification as string");
176822 }
176824 sql_type_list.emplace_back(TransformStringToLogicalType(StringValue::Get(val), context));
176825 }
176827 throw BinderException("read_csv requires at least a single column as input!");
176828 }
176829 } else if (loption == "auto_type_candidates") {
176831 map<uint8_t, LogicalType> candidate_types;
176832
176833
176836
176837 auto &child_type = val.type();
176838 if (child_type.id() != LogicalTypeId::LIST) {
176839 throw BinderException("read_csv auto_types requires a list as input");
176840 }
176841 auto &list_children = ListValue::GetChildren(val);
176842 if (list_children.empty()) {
176843 throw BinderException("auto_type_candidates requires at least one type");
176844 }
176845 for (auto &child : list_children) {
176846 if (child.type().id() != LogicalTypeId::VARCHAR) {
176847 throw BinderException("auto_type_candidates requires a type specification as string");
176848 }
176849 auto candidate_type = TransformStringToLogicalType(StringValue::Get(child), context);
176851 }
176852 for (auto &candidate_type : candidate_types) {
176854 }
176855 } else if (loption == "column_names" || loption == "names") {
176856 unordered_set<string> column_names;
176858 throw BinderException("read_csv column_names/names can only be supplied once");
176859 }
176860 if (val.IsNull()) {
176861 throw BinderException("read_csv %s cannot be NULL", key);
176862 }
176863 auto &children = ListValue::GetChildren(val);
176864 for (auto &child : children) {
176865 if (child.IsNull()) {
176866 throw BinderException("read_csv %s parameter cannot have a NULL value", key);
176867 }
176868 name_list.push_back(StringValue::Get(child));
176869 }
176871 bool empty = true;
176872 for (auto &c : name) {
176873 if (!StringUtil::CharacterIsSpace(c)) {
176874 empty = false;
176875 break;
176876 }
176877 }
176878 if (empty) {
176879 throw BinderException("read_csv %s cannot have empty (or all whitespace) value", key);
176880 }
176881 if (column_names.find(name) != column_names.end()) {
176882 throw BinderException("read_csv %s must have unique values. \"%s\" is repeated.", key, name);
176883 }
176884 column_names.insert(name);
176885 }
176886 } else if (loption == "column_types" || loption == "types" || loption == "dtypes") {
176887 auto &child_type = val.type();
176888 if (child_type.id() != LogicalTypeId::STRUCT && child_type.id() != LogicalTypeId::LIST) {
176889 throw BinderException("read_csv %s requires a struct or list as input", key);
176890 }
176892 throw BinderException("read_csv column_types/types/dtypes can only be supplied once");
176893 }
176894 vector<string> sql_type_names;
176895 if (child_type.id() == LogicalTypeId::STRUCT) {
176896 auto &struct_children = StructValue::GetChildren(val);
176897 D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size());
176898 for (
idx_t i = 0; i < struct_children.size(); i++) {
176899 auto &name = StructType::GetChildName(child_type, i);
176900 auto &val = struct_children[i];
176901 if (val.type().id() != LogicalTypeId::VARCHAR) {
176902 throw BinderException("read_csv %s requires a type specification as string", key);
176903 }
176904 sql_type_names.push_back(StringValue::Get(val));
176906 }
176907 } else {
176908 auto &list_child = ListType::GetChildType(child_type);
176909 if (list_child.id() != LogicalTypeId::VARCHAR) {
176910 throw BinderException("read_csv %s requires a list of types (varchar) as input", key);
176911 }
176912 auto &children = ListValue::GetChildren(val);
176913 for (auto &child : children) {
176914 sql_type_names.push_back(StringValue::Get(child));
176915 }
176916 }
176918 for (auto &sql_type : sql_type_names) {
176919 auto def_type = TransformStringToLogicalType(sql_type, context);
176920 if (def_type.id() == LogicalTypeId::UNBOUND) {
176921 throw BinderException("Unrecognized type \"%s\" for read_csv %s definition", sql_type, key);
176922 }
176924 }
176925 } else if (loption == "all_varchar") {
176927 } else if (loption == "files_to_sniff") {
176930 throw BinderException(
176931 "Unsupported parameter for files_to_sniff: value must be -1 for all files or higher than one.");
176932 }
176933 } else if (loption == "normalize_names") {
176935 } else {
176937 }
176938}
DUCKDB_API string ToSQLString() const
Convert this value to a SQL-parseable string.
Definition duckdb.cpp:133325
static uint8_t GetCandidateSpecificity(const LogicalType &candidate_type)
Definition duckdb.cpp:176701
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
vector< LogicalType > sql_type_list
User-defined SQL type list.
Definition duckdb.hpp:51757
case_insensitive_map_t< idx_t > sql_types_per_column
SQL Type list mapping of name to SQL type index in sql_type_list.
Definition duckdb.hpp:51755
vector< LogicalType > auto_type_candidates
Types considered as candidates for auto-detection ordered by ascending specificity (~ from low to hig...
Definition duckdb.hpp:51763
void SetReadOption(const string &loption, const Value &value, vector< string > &expected_names)
loption - lowercase string set - argument(s) to the option expected_names - names expected if the opt...
Definition duckdb.cpp:176406
int64_t files_to_sniff
In case this is a glob or list of multiple files, how many shall be used to sniff....
Definition duckdb.hpp:51789
bool columns_set
If the names and types were set by the columns parameter.
Definition duckdb.hpp:51761