Skip to content

Commit

Permalink
parse column return_types once only
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Monahan committed Dec 20, 2024
1 parent 866414e commit 85c3f05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/gsheets_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,12 @@ void ReadSheetFunction(ClientContext &context, TableFunctionInput &data_p, DataC
// Adjust starting index based on whether we're using the header
idx_t start_index = bind_data.header ? bind_data.row_index + 1 : bind_data.row_index;

// Determine column types
vector<LogicalType> column_types(column_count, LogicalType::VARCHAR);
if (start_index < sheet_data.values.size()) {
const auto& first_data_row = sheet_data.values[start_index];
for (idx_t col = 0; col < column_count && col < first_data_row.size(); col++) {
const string& value = first_data_row[col];
if (value == "TRUE" || value == "FALSE") {
column_types[col] = LogicalType::BOOLEAN;
} else if (IsValidNumber(value)) {
column_types[col] = LogicalType::DOUBLE;
}
}
}

for (idx_t i = start_index; i < sheet_data.values.size() && row_count < STANDARD_VECTOR_SIZE; i++) {
const auto& row = sheet_data.values[i];
for (idx_t col = 0; col < column_count; col++) {
if (col < row.size()) {
const string& value = row[col];
switch (column_types[col].id()) {
switch (bind_data.return_types[col].id()) {
case LogicalTypeId::BOOLEAN:
if (value.empty()) {
output.SetValue(col, row_count, Value(LogicalType::BOOLEAN));
Expand Down Expand Up @@ -209,6 +195,9 @@ unique_ptr<FunctionData> ReadSheetBind(ClientContext &context, TableFunctionBind
}
}

bind_data->names = names;
bind_data->return_types = return_types;

return bind_data;
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/gsheets_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct ReadSheetBindData : public TableFunctionData {
string response;
bool header;
string sheet_name;
vector<LogicalType> return_types;
vector<string> names;

ReadSheetBindData(string spreadsheet_id, string token, bool header, string sheet_name);
};
Expand Down

0 comments on commit 85c3f05

Please sign in to comment.