|
19 | 19 |
|
20 | 20 | #include "iceberg/update/update_properties.h" |
21 | 21 |
|
| 22 | +#include <charconv> |
22 | 23 | #include <cstdint> |
23 | 24 | #include <memory> |
| 25 | +#include <system_error> |
24 | 26 |
|
25 | 27 | #include "iceberg/metrics_config.h" |
26 | 28 | #include "iceberg/result.h" |
@@ -83,21 +85,23 @@ Result<PendingUpdate::ApplyResult> UpdateProperties::Apply() { |
83 | 85 |
|
84 | 86 | auto iter = updates_.find(TableProperties::kFormatVersion.key()); |
85 | 87 | if (iter != updates_.end()) { |
86 | | - try { |
87 | | - int parsed_version = std::stoi(iter->second); |
88 | | - if (parsed_version > TableMetadata::kSupportedTableFormatVersion) { |
89 | | - return InvalidArgument( |
90 | | - "Cannot upgrade table to unsupported format version: v{} (supported: v{})", |
91 | | - parsed_version, TableMetadata::kSupportedTableFormatVersion); |
92 | | - } |
93 | | - format_version_ = static_cast<int8_t>(parsed_version); |
94 | | - } catch (const std::invalid_argument& e) { |
95 | | - return InvalidArgument("Invalid format version '{}': not a valid integer", |
96 | | - iter->second); |
97 | | - } catch (const std::out_of_range& e) { |
98 | | - return InvalidArgument("Format version '{}' is out of range", iter->second); |
| 88 | + int parsed_version = 0; |
| 89 | + const auto& val = iter->second; |
| 90 | + auto [ptr, ec] = std::from_chars(val.data(), val.data() + val.size(), parsed_version); |
| 91 | + |
| 92 | + if (ec == std::errc::invalid_argument) { |
| 93 | + return InvalidArgument("Invalid format version '{}': not a valid integer", val); |
| 94 | + } else if (ec == std::errc::result_out_of_range) { |
| 95 | + return InvalidArgument("Format version '{}' is out of range", val); |
99 | 96 | } |
100 | 97 |
|
| 98 | + if (parsed_version > TableMetadata::kSupportedTableFormatVersion) { |
| 99 | + return InvalidArgument( |
| 100 | + "Cannot upgrade table to unsupported format version: v{} (supported: v{})", |
| 101 | + parsed_version, TableMetadata::kSupportedTableFormatVersion); |
| 102 | + } |
| 103 | + format_version_ = static_cast<int8_t>(parsed_version); |
| 104 | + |
101 | 105 | updates_.erase(iter); |
102 | 106 | } |
103 | 107 |
|
|
0 commit comments