diff --git a/src/motherduck_destination_server.cpp b/src/motherduck_destination_server.cpp index d9511cb..cbbac64 100644 --- a/src/motherduck_destination_server.cpp +++ b/src/motherduck_destination_server.cpp @@ -207,18 +207,26 @@ grpc::Status DestinationSdkImpl::DescribeTable( return ::grpc::Status(::grpc::StatusCode::OK, ""); } + mdlog::info("Endpoint : table exists; getting columns"); auto duckdb_columns = describe_table(*con, table_name); + mdlog::info("Endpoint : got columns"); fivetran_sdk::Table *table = response->mutable_table(); table->set_name(get_table_name(request)); for (auto &col : duckdb_columns) { + mdlog::info("Endpoint : processing column " + col.name); fivetran_sdk::Column *ft_col = table->mutable_columns()->Add(); ft_col->set_name(col.name); - ft_col->set_type(get_fivetran_type(col.type)); + const auto fivetran_type = get_fivetran_type(col.type); + mdlog::info("Endpoint : column type = " + + std::to_string(fivetran_type)); + ft_col->set_type(fivetran_type); ft_col->set_primary_key(col.primary_key); - ft_col->mutable_decimal()->set_precision(col.width); - ft_col->mutable_decimal()->set_scale(col.scale); + if (fivetran_type == fivetran_sdk::DECIMAL) { + ft_col->mutable_decimal()->set_precision(col.width); + ft_col->mutable_decimal()->set_scale(col.scale); + } } } catch (const std::exception &e) { diff --git a/src/sql_generator.cpp b/src/sql_generator.cpp index 8c91106..2d1ca9e 100644 --- a/src/sql_generator.cpp +++ b/src/sql_generator.cpp @@ -186,7 +186,6 @@ std::vector describe_table(duckdb::Connection &con, // TBD is_identity is never set, used is_nullable=no temporarily but really // should use duckdb_constraints table. - // TBD scale/precision std::vector columns; auto query = "SELECT " @@ -221,7 +220,7 @@ std::vector describe_table(duckdb::Connection &con, duckdb::LogicalTypeId column_type = static_cast(row.GetValue(1).GetValue()); column_def col{row.GetValue(0).GetValue(), column_type, - row.GetValue(2).GetValue()}; + row.GetValue(2).GetValue(), 0, 0}; if (column_type == duckdb::LogicalTypeId::DECIMAL) { col.width = row.GetValue(3).GetValue(); col.scale = row.GetValue(4).GetValue(); diff --git a/test/integration/test_server.cpp b/test/integration/test_server.cpp index acc322e..8051670 100644 --- a/test/integration/test_server.cpp +++ b/test/integration/test_server.cpp @@ -145,6 +145,7 @@ TEST_CASE("CreateTable, DescribeTable for existing table, AlterTable", REQUIRE(response.table().columns(0).name() == "id"); REQUIRE(response.table().columns(0).type() == ::fivetran_sdk::DataType::STRING); + REQUIRE_FALSE(response.table().columns(0).has_decimal()); } } @@ -1164,6 +1165,7 @@ TEST_CASE("Test all types with create and describe table") { REQUIRE(response.table().columns(2).name() == "col_decimal"); REQUIRE(response.table().columns(2).type() == ::fivetran_sdk::DataType::DECIMAL); + REQUIRE(response.table().columns(2).has_decimal()); REQUIRE(response.table().columns(2).decimal().scale() == 11); REQUIRE(response.table().columns(2).decimal().precision() == 20); REQUIRE_FALSE(response.table().columns(2).primary_key());