Skip to content

Commit

Permalink
handle csv block size being empty string (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrl20 authored Aug 2, 2024
1 parent 4e6ee3d commit 73325dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/motherduck_destination_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int find_optional_property(
const std::string &property_name, int default_value,
const std::function<int(const std::string &)> &parse) {
auto token_it = config.find(property_name);
return token_it == config.end() ? default_value : parse(token_it->second);
return token_it == config.end() || token_it->second.empty() ? default_value : parse(token_it->second);
}

template <typename T> std::string get_schema_name(const T *request) {
Expand Down
36 changes: 33 additions & 3 deletions test/integration/test_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ TEST_CASE("Test endpoint fails when token is bad",
auto status = service.Test(nullptr, &request, &response);
REQUIRE_NO_FAIL(status);
CHECK_THAT(status.error_message(),
Catch::Matchers::ContainsSubstring("UNAUTHENTICATED"));
CHECK_THAT(status.error_message(),
Catch::Matchers::ContainsSubstring("UNAUTHENTICATED"));
Catch::Matchers::ContainsSubstring("not authenticated"));
}

TEST_CASE(
Expand Down Expand Up @@ -935,6 +933,38 @@ TEST_CASE("Table with large json row", "[integration][write-batch]") {
REQUIRE(res->GetValue(0, 0) == 0);
}

{
// Empty string for the block size falls back to default value,
// but sync fails due to default block size being too small.
::fivetran_sdk::WriteBatchRequest request;
(*request.mutable_configuration())["motherduck_token"] = token;
(*request.mutable_configuration())["motherduck_database"] =
TEST_DATABASE_NAME;
(*request.mutable_configuration())[MD_PROP_CSV_BLOCK_SIZE] = "";

make_book_table(request, table_name);

const std::string filename = "huge_books.csv";
const std::string filepath = TEST_RESOURCES_DIR + filename;

request.add_replace_files(filepath);

::fivetran_sdk::WriteBatchResponse response;
auto status = service.WriteBatch(nullptr, &request, &response);
REQUIRE_FALSE(status.ok());
CHECK_THAT(status.error_message(),
Catch::Matchers::ContainsSubstring(
"straddling object straddles two block boundaries"));
}

{
// check no rows were inserted
auto res = con->Query("SELECT count(*) FROM " + table_name);
REQUIRE_NO_FAIL(res);
REQUIRE(res->RowCount() == 1);
REQUIRE(res->GetValue(0, 0) == 0);
}

{
// succeed when block_size is increased
::fivetran_sdk::WriteBatchRequest request;
Expand Down

0 comments on commit 73325dc

Please sign in to comment.