Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/iceberg/test/table_metadata_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ TEST(TableMetadataTest, InvalidProperties) {
"Table property {} must have non negative integer value, but got {}",
TableProperties::kCommitNumRetries.key(), -1)));
}

{
// Commit properties must contain only an integer, not a valid integer prefix.
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
for (const auto& value : {"4x", "1.5"}) {
std::unordered_map<std::string, std::string> invalid_commit_properties = {
{TableProperties::kCommitNumRetries.key(), value}};

auto res = TableMetadata::Make(*schema, *spec, *order, "s3://bucket/test",
invalid_commit_properties);
EXPECT_THAT(res, IsError(ErrorKind::kValidationFailed));
EXPECT_THAT(res, HasErrorMessage(std::format(
"Table property {} must have integer value, but got {}",
TableProperties::kCommitNumRetries.key(), value)));
}
}
}

// test construction of TableMetadataBuilder
Expand Down
13 changes: 5 additions & 8 deletions src/iceberg/util/property_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@

#include "iceberg/util/property_util.h"

#include <charconv>
#include <cstdint>

#include "iceberg/table_properties.h"
#include "iceberg/util/string_util.h"

namespace iceberg {

Status PropertyUtil::ValidateCommitProperties(
const std::unordered_map<std::string, std::string>& properties) {
for (const auto& property : TableProperties::commit_properties()) {
if (auto it = properties.find(property); it != properties.end()) {
int32_t parsed;
auto [ptr, ec] = std::from_chars(it->second.data(),
it->second.data() + it->second.size(), parsed);
if (ec == std::errc::invalid_argument) {
auto parsed_result = StringUtils::ParseNumber<int32_t>(it->second);
if (!parsed_result) {
return ValidationFailed("Table property {} must have integer value, but got {}",
property, it->second);
} else if (ec == std::errc::result_out_of_range) {
return ValidationFailed("Table property {} value out of range {}", property,
it->second);
}
const auto parsed = *parsed_result;
if (parsed < 0) {
return ValidationFailed(
"Table property {} must have non negative integer value, but got {}",
Expand Down
Loading