Skip to content

Commit

Permalink
fix reading maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
archiewood committed Nov 3, 2024
1 parent 9979eb6 commit ef816eb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/gsheets_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ ReadSheetBindData::ReadSheetBindData(string spreadsheet_id, string token, bool h
response = call_sheets_api(spreadsheet_id, token, sheet_name, HttpMethod::GET);
}

bool IsValidNumber(const string& value) {
// Skip empty strings
if (value.empty()) {
return false;
}

try {
// Try to parse as double
size_t processed;
std::stod(value, &processed);
// Ensure the entire string was processed
return processed == value.length();
} catch (...) {
return false;
}
}

void ReadSheetFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
auto &bind_data = const_cast<ReadSheetBindData&>(data_p.bind_data->Cast<ReadSheetBindData>());
Expand All @@ -40,7 +56,7 @@ void ReadSheetFunction(ClientContext &context, TableFunctionInput &data_p, DataC
const string& value = first_data_row[col];
if (value == "true" || value == "false") {
column_types[col] = LogicalType::BOOLEAN;
} else if (value.find_first_not_of("0123456789.+-eE") == string::npos) {
} else if (IsValidNumber(value)) {
column_types[col] = LogicalType::DOUBLE;
}
}
Expand Down Expand Up @@ -155,7 +171,7 @@ unique_ptr<FunctionData> ReadSheetBind(ClientContext &context, TableFunctionBind
const string& value = first_data_row[i];
if (value == "true" || value == "false") {
return_types.push_back(LogicalType::BOOLEAN);
} else if (value.find_first_not_of("0123456789.+-eE") == string::npos) {
} else if (IsValidNumber(value)) {
return_types.push_back(LogicalType::DOUBLE);
} else {
return_types.push_back(LogicalType::VARCHAR);
Expand Down

0 comments on commit ef816eb

Please sign in to comment.