Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip the optional decimal field if type is not decimal; add logging #50

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/motherduck_destination_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,26 @@ grpc::Status DestinationSdkImpl::DescribeTable(
return ::grpc::Status(::grpc::StatusCode::OK, "");
}

mdlog::info("Endpoint <DescribeTable>: table exists; getting columns");
auto duckdb_columns = describe_table(*con, table_name);
mdlog::info("Endpoint <DescribeTable>: got columns");

fivetran_sdk::Table *table = response->mutable_table();
table->set_name(get_table_name(request));

for (auto &col : duckdb_columns) {
mdlog::info("Endpoint <DescribeTable>: 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 <DescribeTable>: 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) {
Expand Down
3 changes: 1 addition & 2 deletions src/sql_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ std::vector<column_def> 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<column_def> columns;

auto query = "SELECT "
Expand Down Expand Up @@ -221,7 +220,7 @@ std::vector<column_def> describe_table(duckdb::Connection &con,
duckdb::LogicalTypeId column_type =
static_cast<duckdb::LogicalTypeId>(row.GetValue(1).GetValue<int8_t>());
column_def col{row.GetValue(0).GetValue<duckdb::string>(), column_type,
row.GetValue(2).GetValue<bool>()};
row.GetValue(2).GetValue<bool>(), 0, 0};
if (column_type == duckdb::LogicalTypeId::DECIMAL) {
col.width = row.GetValue(3).GetValue<uint32_t>();
col.scale = row.GetValue(4).GetValue<uint32_t>();
Expand Down
2 changes: 2 additions & 0 deletions test/integration/test_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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());
Expand Down
Loading