Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/iceberg/json_serde.cc
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ Result<std::unique_ptr<Type>> TypeFromJson(const nlohmann::json& json) {
StringUtils::ParseNumber<int32_t>(match[1].str()));
ICEBERG_ASSIGN_OR_RAISE(auto scale,
StringUtils::ParseNumber<int32_t>(match[2].str()));
if (precision > DecimalType::kMaxPrecision) {
return JsonParseError("Invalid decimal type: {}", type_name);
}
return std::make_unique<DecimalType>(precision, scale);
}
return JsonParseError("Invalid decimal type: {}", type_name);
Expand Down
7 changes: 7 additions & 0 deletions src/iceberg/test/schema_json_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ INSTANTIATE_TEST_SUITE_P(
SchemaField::MakeRequired(1, "id", iceberg::int32()),
SchemaField::MakeOptional(2, "name", iceberg::string())})}));

TEST(TypeJsonTest, FromJsonOutOfRangeDecimalPrecisionIsParseError) {
// Precision beyond the supported maximum must surface as a parse error,
// not an uncaught IcebergError from the DecimalType constructor.
auto result = TypeFromJson(nlohmann::json::parse("\"decimal(39, 2)\""));
EXPECT_THAT(result, IsError(ErrorKind::kJsonParseError));
}

TEST(TypeJsonTest, FromJsonWithSpaces) {
auto fixed_json = R"("fixed[ 8 ]")";
auto fixed_result = TypeFromJson(nlohmann::json::parse(fixed_json));
Expand Down
Loading