Skip to content

Commit

Permalink
Merge pull request #36 from evidence-dev/safe-read-nulls
Browse files Browse the repository at this point in the history
fix Bug with failing double conversion #34
  • Loading branch information
archiewood authored Nov 1, 2024
2 parents 436707e + 4988473 commit 5ae899f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/gsheets_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ void ReadSheetFunction(ClientContext &context, TableFunctionInput &data_p, DataC
const string& value = row[col];
switch (column_types[col].id()) {
case LogicalTypeId::BOOLEAN:
output.SetValue(col, row_count, Value::BOOLEAN(value == "true"));
if (value.empty()) {
output.SetValue(col, row_count, Value(LogicalType::BOOLEAN));
} else {
output.SetValue(col, row_count, Value(value).DefaultCastAs(LogicalType::BOOLEAN));
}
break;
case LogicalTypeId::DOUBLE:
output.SetValue(col, row_count, Value::DOUBLE(std::stod(value)));
if (value.empty()) {
output.SetValue(col, row_count, Value(LogicalType::DOUBLE));
} else {
output.SetValue(col, row_count, Value(value).DefaultCastAs(LogicalType::DOUBLE));
}
break;
default:
output.SetValue(col, row_count, Value(value));
Expand Down
8 changes: 8 additions & 0 deletions test/sql/read_gsheet.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ NULL
NULL
99.0

# Issue 34: stod() fails on empty strings
query III
FROM read_gsheet('https://docs.google.com/spreadsheets/d/11QdEasMWbETbFVxry-SsD8jVcdYIT1zBQszcF84MdE8/edit?gid=732080485#gid=732080485');
----
1.0 value1 blabla1
2.0 value2 blabla2
3.0 value3 blabla3
NULL value4 blabla4

# Drop the secret
statement ok
Expand Down

0 comments on commit 5ae899f

Please sign in to comment.