Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/patches/extensions/excel/excel_copy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/src/excel/xlsx/copy_xlsx.cpp b/src/excel/xlsx/copy_xlsx.cpp
index 33890b5..f91adf6 100644
--- a/src/excel/xlsx/copy_xlsx.cpp
+++ b/src/excel/xlsx/copy_xlsx.cpp
@@ -392,7 +392,7 @@ static void SetVarcharValue(named_parameter_map_t &params, const string &key, co
params[key] = val.back();
}

-static void ParseCopyFromOptions(XLSXReadData &data, case_insensitive_map_t<vector<Value>> &options) {
+static void ParseCopyFromOptions(XLSXReadData &data, const case_insensitive_map_t<vector<Value>> &options) {

// Just make it really easy for us, extract everything into a named parameter map
named_parameter_map_t named_parameters;
@@ -421,16 +421,16 @@ static void ParseCopyFromOptions(XLSXReadData &data, case_insensitive_map_t<vect
ReadXLSX::ParseOptions(data.options, named_parameters);
}

-static unique_ptr<FunctionData> CopyFromBind(ClientContext &context, CopyInfo &info, vector<string> &expected_names,
+static unique_ptr<FunctionData> CopyFromBind(ClientContext &context, CopyFromFunctionBindInput &input, vector<string> &expected_names,
vector<LogicalType> &expected_types) {

auto result = make_uniq<XLSXReadData>();
- result->file_path = info.file_path;
+ result->file_path = input.info.file_path;

// TODO: Parse options
- ParseCopyFromOptions(*result, info.options);
+ ParseCopyFromOptions(*result, input.info.options);

- ZipFileReader archive(context, info.file_path);
+ ZipFileReader archive(context, input.info.file_path);
ReadXLSX::ResolveSheet(result, archive);

// Column count mismatch!
6 changes: 3 additions & 3 deletions src/include/duckdb/common/multi_file/multi_file_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ class MultiFileFunction : public TableFunction {
std::move(file_options), std::move(options), std::move(interface));
}

static unique_ptr<FunctionData> MultiFileBindCopy(ClientContext &context, CopyInfo &info,
static unique_ptr<FunctionData> MultiFileBindCopy(ClientContext &context, CopyFromFunctionBindInput &input,
vector<string> &expected_names,
vector<LogicalType> &expected_types) {
auto multi_file_reader = MultiFileReader::CreateDefault("COPY");
vector<string> paths = {info.file_path};
vector<string> paths = {input.info.file_path};
auto file_list = multi_file_reader->CreateFileList(context, paths);

auto interface = OP::InitializeInterface(context, *multi_file_reader, *file_list);

auto options = interface->InitializeOptions(context, nullptr);
MultiFileOptions file_options;

for (auto &option : info.options) {
for (auto &option : input.info.options) {
auto loption = StringUtil::Lower(option.first);
if (interface->ParseCopyOption(context, loption, option.second, *options, expected_names, expected_types)) {
continue;
Expand Down
10 changes: 9 additions & 1 deletion src/include/duckdb/function/copy_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ struct CopyFunctionBindInput {
string file_extension;
};

struct CopyFromFunctionBindInput {
explicit CopyFromFunctionBindInput(const CopyInfo &info_p, TableFunction &tf_p) : info(info_p), tf(tf_p) {
}

const CopyInfo &info;
TableFunction &tf;
};

struct CopyToSelectInput {
ClientContext &context;
case_insensitive_map_t<vector<Value>> &options;
Expand All @@ -102,7 +110,7 @@ typedef void (*copy_to_serialize_t)(Serializer &serializer, const FunctionData &

typedef unique_ptr<FunctionData> (*copy_to_deserialize_t)(Deserializer &deserializer, CopyFunction &function);

typedef unique_ptr<FunctionData> (*copy_from_bind_t)(ClientContext &context, CopyInfo &info,
typedef unique_ptr<FunctionData> (*copy_from_bind_t)(ClientContext &context, CopyFromFunctionBindInput &info,
vector<string> &expected_names,
vector<LogicalType> &expected_types);
typedef CopyFunctionExecutionMode (*copy_to_execution_mode_t)(bool preserve_insertion_order, bool supports_batch_index);
Expand Down
4 changes: 2 additions & 2 deletions src/planner/binder/statement/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ BoundStatement Binder::BindCopyFrom(CopyStatement &stmt) {
expected_names.push_back(col.Name());
}
}

CopyFromFunctionBindInput input(*stmt.info, copy_function.function.copy_from_function);
auto function_data =
copy_function.function.copy_from_bind(context, *stmt.info, expected_names, bound_insert.expected_types);
copy_function.function.copy_from_bind(context, input, expected_names, bound_insert.expected_types);
auto get = make_uniq<LogicalGet>(GenerateTableIndex(), copy_function.function.copy_from_function,
std::move(function_data), bound_insert.expected_types, expected_names);
for (idx_t i = 0; i < bound_insert.expected_types.size(); i++) {
Expand Down
Loading