11#include < utility>
22
3- #include " duckdb/common/case_insensitive_map.hpp"
43#include " duckdb/common/exception.hpp"
54#include " duckdb/common/exception/binder_exception.hpp"
65#include " duckdb/common/file_system.hpp"
109#include " gsheets_copy.hpp"
1110#include " gsheets_utils.hpp"
1211
12+ #include " utils/options.hpp"
13+
1314#include " sheets/auth_factory.hpp"
1415#include " sheets/client.hpp"
1516#include " sheets/exception.hpp"
@@ -26,58 +27,20 @@ GSheetCopyFunction::GSheetCopyFunction() : CopyFunction("gsheet") {
2627 copy_to_sink = GSheetWriteSink;
2728}
2829
29- static std::string GetStringOption (const case_insensitive_map_t <vector<Value>> &options, const std::string &name,
30- const std::string &default_value = " " ) {
31- const auto it = options.find (name);
32- if (it == options.end ()) {
33- return default_value;
34- }
35- std::string err;
36- Value val;
37- if (!it->second .back ().DefaultTryCastAs (LogicalType::VARCHAR, val, &err)) {
38- throw BinderException (name + " option must be VARCHAR" );
39- }
40- if (val.IsNull ()) {
41- throw BinderException (name + " option must not be NULL" );
42- }
43- return StringValue::Get (val);
44- }
45-
46- // NOTE: the second value in pair is a flag indicating if the value was set by the user
47- static std::pair<bool , bool > GetBoolOption (const case_insensitive_map_t <vector<Value>> &options,
48- const std::string &name, bool default_value = false ) {
49- const auto it = options.find (name);
50- if (it == options.end ()) {
51- return std::make_pair (default_value, false );
52- }
53- if (it->second .size () != 1 ) {
54- throw BinderException (name + " option must be a single boolean value" );
55- }
56- std::string err;
57- Value val;
58- if (!it->second .back ().DefaultTryCastAs (LogicalType::BOOLEAN, val, &err)) {
59- throw BinderException (name + " option must be a single boolean value" );
60- }
61- if (val.IsNull ()) {
62- throw BinderException (name + " option must be a single boolean value" );
63- }
64- return std::make_pair (BooleanValue::Get (val), true );
65- }
66-
6730unique_ptr<FunctionData> GSheetCopyFunction::GSheetWriteBind (ClientContext &context, CopyFunctionBindInput &input,
6831 const vector<string> &names,
6932 const vector<LogicalType> &sql_types) {
7033
7134 string file_path = input.info .file_path ;
7235 auto options = input.info .options ;
7336
74- auto sheet = GetStringOption (options, " sheet" );
75- auto range = GetStringOption (options, " range" );
76- bool overwrite_sheet = GetBoolOption (options, " overwrite_sheet" , true ).first ;
77- bool overwrite_range = GetBoolOption (options, " overwrite_range" , false ).first ;
78- bool create_if_not_exists = GetBoolOption (options, " create_if_not_exists" , false ).first ;
37+ auto sheet = duckdb::sheets:: GetStringOption (options, " sheet" );
38+ auto range = duckdb::sheets:: GetStringOption (options, " range" );
39+ bool overwrite_sheet = duckdb::sheets:: GetBoolOption (options, " overwrite_sheet" , true ).first ;
40+ bool overwrite_range = duckdb::sheets:: GetBoolOption (options, " overwrite_range" , false ).first ;
41+ bool create_if_not_exists = duckdb::sheets:: GetBoolOption (options, " create_if_not_exists" , false ).first ;
7942
80- auto header_result = GetBoolOption (options, " header" , true );
43+ auto header_result = duckdb::sheets:: GetBoolOption (options, " header" , true );
8144 bool header = header_result.second ? header_result.first : (overwrite_range || overwrite_sheet);
8245
8346 if (create_if_not_exists && sheet.empty ()) {
0 commit comments