From 0dad35f2a9dc73f0ad1e6493ae67576269263e88 Mon Sep 17 00:00:00 2001 From: Elena Felder <41136058+elefeint@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:54:57 -0400 Subject: [PATCH] Check for optional field presence before using them (#47) --- includes/motherduck_destination_server.hpp | 4 ++++ src/motherduck_destination_server.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/motherduck_destination_server.hpp b/includes/motherduck_destination_server.hpp index 2106020..bc2946b 100644 --- a/includes/motherduck_destination_server.hpp +++ b/includes/motherduck_destination_server.hpp @@ -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; diff --git a/src/motherduck_destination_server.cpp b/src/motherduck_destination_server.cpp index 92c4113..41eb054 100644 --- a/src/motherduck_destination_server.cpp +++ b/src/motherduck_destination_server.cpp @@ -62,9 +62,10 @@ std::vector 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; } @@ -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() +