Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/iceberg/avro/avro_schema_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

#include <charconv>
#include <format>
#include <mutex>
#include <string_view>
Expand Down Expand Up @@ -413,11 +414,13 @@ Result<int32_t> GetId(const ::avro::NodePtr& node, const std::string& attr_name,
return InvalidSchema("Missing avro attribute: {}", attr_name);
}

try {
return std::stoi(id_str.value());
} catch (const std::exception& e) {
return InvalidSchema("Invalid {}: {}", attr_name, id_str.value());
int32_t id;
const auto& id_value = id_str.value();
auto [_, ec] = std::from_chars(id_value.data(), id_value.data() + id_value.size(), id);
if (ec != std::errc()) {
return InvalidSchema("Invalid {}: {}", attr_name, id_value);
}
return id;
}

Result<int32_t> GetElementId(const ::avro::NodePtr& node) {
Expand Down
7 changes: 6 additions & 1 deletion src/iceberg/schema_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "iceberg/schema_internal.h"

#include <charconv>
#include <cstring>
#include <optional>
#include <string>
Expand Down Expand Up @@ -192,7 +193,11 @@ int32_t GetFieldId(const ArrowSchema& schema) {
return kUnknownFieldId;
}

return std::stoi(std::string(field_id_value.data, field_id_value.size_bytes));
int32_t field_id = kUnknownFieldId;
std::from_chars(field_id_value.data, field_id_value.data + field_id_value.size_bytes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this check the ec return also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ec is std::errc(), the field_id is still kUnknownFieldId, this check is unnecessary.

field_id);

return field_id;
}

Result<std::shared_ptr<Type>> FromArrowSchema(const ArrowSchema& schema) {
Expand Down
3 changes: 2 additions & 1 deletion test/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* under the License.
*/

#include "iceberg/util/config.h"

#include <string>

#include <gtest/gtest.h>
#include <iceberg/util/config.h>

namespace iceberg {

Expand Down
2 changes: 1 addition & 1 deletion test/partition_field_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <format>

#include <gtest/gtest.h>
#include <iceberg/type.h>

#include "iceberg/transform.h"
#include "iceberg/type.h"
#include "iceberg/util/formatter.h" // IWYU pragma: keep

namespace iceberg {
Expand Down
2 changes: 1 addition & 1 deletion test/partition_spec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <iceberg/schema_field.h>

#include "iceberg/partition_field.h"
#include "iceberg/schema.h"
#include "iceberg/schema_field.h"
#include "iceberg/transform.h"
#include "iceberg/util/formatter.h" // IWYU pragma: keep

Expand Down
Loading