WZhuo commented on code in PR #437:
URL: https://github.com/apache/iceberg-cpp/pull/437#discussion_r2647401306
##########
src/iceberg/schema.cc:
##########
@@ -228,4 +243,33 @@ Result<std::vector<std::string>>
Schema::IdentifierFieldNames() const {
return names;
}
+Result<int32_t> Schema::HighestFieldId() const { return
highest_field_id_.Get(*this); }
+
+bool Schema::SameSchema(const Schema& other) const {
+ return fields_ == other.fields_ && identifier_field_ids_ ==
other.identifier_field_ids_;
+}
+
+Status Schema::Validate(int32_t format_version) const {
+ // Get all fields including nested ones
+ ICEBERG_ASSIGN_OR_RAISE(auto id_to_field, id_to_field_.Get(*this));
+
+ // Check each field's type and defaults
+ for (const auto& [field_id, field_ref] : id_to_field.get()) {
+ const auto& field = field_ref.get();
+
+ // Check if the field's type requires a minimum format version
+ if (auto it =
TableMetadata::kMinFormatVersions.find(field.type()->type_id());
+ it != TableMetadata::kMinFormatVersions.end()) {
+ if (int32_t min_format_version = it->second; format_version <
min_format_version) {
+ return InvalidSchema("Invalid type for {}: {} is not supported until
v{}",
+ field.name(), *field.type(), min_format_version);
+ }
+ }
+
+ // TODO(GuoTao.yu): Check default values when they are supported
Review Comment:
I think `Schema.validateIdentifierField` should be called in Schema::Make, I
can do it in a seperate PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]