1919
2020#include " iceberg/schema_internal.h"
2121
22- #include < cerrno>
23- #include < charconv>
2422#include < cstring>
2523#include < optional>
2624#include < string>
3028#include " iceberg/schema.h"
3129#include " iceberg/type.h"
3230#include " iceberg/util/macros.h"
31+ #include " iceberg/util/string_util.h"
3332
3433namespace iceberg {
3534
@@ -228,7 +227,7 @@ Status ToArrowSchema(const Schema& schema, ArrowSchema* out) {
228227
229228namespace {
230229
231- int32_t GetFieldId (const ArrowSchema& schema) {
230+ Result< int32_t > GetFieldId (const ArrowSchema& schema) {
232231 if (schema.metadata == nullptr ) {
233232 return kUnknownFieldId ;
234233 }
@@ -241,19 +240,21 @@ int32_t GetFieldId(const ArrowSchema& schema) {
241240 return kUnknownFieldId ;
242241 }
243242
244- int32_t field_id = kUnknownFieldId ;
245- std::from_chars (field_id_value.data , field_id_value.data + field_id_value.size_bytes ,
246- field_id);
243+ std::string_view field_id (field_id_value.data , field_id_value.size_bytes );
244+ auto field_id_result = StringUtils::ParseNumber<int32_t >(field_id);
245+ if (!field_id_result.has_value ()) {
246+ return InvalidSchema (" Invalid Arrow field ID: '{}'" , field_id);
247+ }
247248
248- return field_id ;
249+ return field_id_result. value () ;
249250}
250251
251252Result<std::shared_ptr<Type>> FromArrowSchema (const ArrowSchema& schema) {
252253 auto to_schema_field =
253254 [](const ArrowSchema& schema) -> Result<std::unique_ptr<SchemaField>> {
254255 ICEBERG_ASSIGN_OR_RAISE (auto field_type, FromArrowSchema (schema));
255256
256- auto field_id = GetFieldId (schema);
257+ ICEBERG_ASSIGN_OR_RAISE ( auto field_id, GetFieldId (schema) );
257258 bool is_optional = (schema.flags & ARROW_FLAG_NULLABLE ) != 0 ;
258259 if (field_type->type_id () == TypeId::kUnknown && !is_optional) {
259260 return InvalidSchema (" Arrow null field '{}' must be nullable" , schema.name );
0 commit comments