Skip to content

Commit

Permalink
Check for optional field presence before using them (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
elefeint authored Aug 16, 2024
1 parent 4140bda commit 0dad35f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions includes/motherduck_destination_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ static constexpr const char *const CONFIG_TEST_NAME_AUTHENTICATE =
static constexpr const char *const CONFIG_TEST_NAME_CSV_BLOCK_SIZE =
"test_csv_block_size";

static constexpr const int DUCKDB_DEFAULT_PRECISION = 18;

static constexpr const int DUCKDB_DEFAULT_SCALE = 3;

class DestinationSdkImpl final : public fivetran_sdk::Destination::Service {
public:
DestinationSdkImpl() = default;
Expand Down
8 changes: 5 additions & 3 deletions src/motherduck_destination_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ std::vector<column_def> get_duckdb_columns(
DataType_Name(col.type()) + "> for column <" +
col.name() + "> to a DuckDB type");
}
auto precision = col.has_decimal() ? col.decimal().precision() : DUCKDB_DEFAULT_PRECISION;
auto scale = col.has_decimal() ? col.decimal().scale() : DUCKDB_DEFAULT_SCALE;
duckdb_columns.push_back(column_def{col.name(), ddbtype, col.primary_key(),
col.decimal().precision(),
col.decimal().scale()});
precision, scale});
}
return duckdb_columns;
}
Expand Down Expand Up @@ -310,8 +311,9 @@ DestinationSdkImpl::Truncate(::grpc::ServerContext *context,
std::chrono::nanoseconds delete_before_ts =
std::chrono::seconds(request->utc_delete_before().seconds()) +
std::chrono::nanoseconds(request->utc_delete_before().nanos());
const std::string deleted_column = request->has_soft() ? request->soft().deleted_column() : "";
truncate_table(*con, table_name, request->synced_column(),
delete_before_ts, request->soft().deleted_column());
delete_before_ts, deleted_column);
} else {
mdlog::warning("Table <" + request->table_name() +
"> not found in schema <" + request->schema_name() +
Expand Down

0 comments on commit 0dad35f

Please sign in to comment.