|
47 | 47 | #include "iceberg/util/formatter.h" // IWYU pragma: keep |
48 | 48 | #include "iceberg/util/json_util_internal.h" |
49 | 49 | #include "iceberg/util/macros.h" |
| 50 | +#include "iceberg/util/string_util.h" |
50 | 51 | #include "iceberg/util/timepoint.h" |
51 | 52 |
|
52 | 53 | namespace iceberg { |
@@ -497,15 +498,20 @@ Result<std::unique_ptr<Type>> TypeFromJson(const nlohmann::json& json) { |
497 | 498 | std::regex fixed_regex(R"(fixed\[\s*(\d+)\s*\])"); |
498 | 499 | std::smatch match; |
499 | 500 | if (std::regex_match(type_str, match, fixed_regex)) { |
500 | | - return std::make_unique<FixedType>(std::stoi(match[1].str())); |
| 501 | + ICEBERG_ASSIGN_OR_RAISE(auto length, |
| 502 | + StringUtils::ParseNumber<int32_t>(match[1].str())); |
| 503 | + return std::make_unique<FixedType>(length); |
501 | 504 | } |
502 | 505 | return JsonParseError("Invalid fixed type: {}", type_str); |
503 | 506 | } else if (type_str.starts_with("decimal")) { |
504 | 507 | std::regex decimal_regex(R"(decimal\(\s*(\d+)\s*,\s*(\d+)\s*\))"); |
505 | 508 | std::smatch match; |
506 | 509 | if (std::regex_match(type_str, match, decimal_regex)) { |
507 | | - return std::make_unique<DecimalType>(std::stoi(match[1].str()), |
508 | | - std::stoi(match[2].str())); |
| 510 | + ICEBERG_ASSIGN_OR_RAISE(auto precision, |
| 511 | + StringUtils::ParseNumber<int32_t>(match[1].str())); |
| 512 | + ICEBERG_ASSIGN_OR_RAISE(auto scale, |
| 513 | + StringUtils::ParseNumber<int32_t>(match[2].str())); |
| 514 | + return std::make_unique<DecimalType>(precision, scale); |
509 | 515 | } |
510 | 516 | return JsonParseError("Invalid decimal type: {}", type_str); |
511 | 517 | } else { |
|
0 commit comments