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

handle csv block size being empty string #46

Merged
merged 1 commit into from
Aug 2, 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
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
Loading