-
Notifications
You must be signed in to change notification settings - Fork 76
feat: add schema update to table metadata builder #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b9ffb30
059f346
0ef9e1e
bf43662
14c3b0c
16e797e
4822613
38cc693
d0e7054
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include "iceberg/result.h" | ||
| #include "iceberg/row/struct_like.h" | ||
| #include "iceberg/schema_internal.h" | ||
| #include "iceberg/table_metadata.h" | ||
| #include "iceberg/type.h" | ||
| #include "iceberg/util/formatter.h" // IWYU pragma: keep | ||
| #include "iceberg/util/macros.h" | ||
|
|
@@ -147,6 +148,20 @@ Result<std::unordered_map<int32_t, std::vector<size_t>>> Schema::InitIdToPositio | |
| return visitor.Finish(); | ||
| } | ||
|
|
||
| Result<int32_t> Schema::InitHighestFieldId(const Schema& self) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto id_to_field, self.id_to_field_.Get(self)); | ||
|
|
||
| if (id_to_field.get().empty()) { | ||
| return kInitialColumnId; | ||
| } | ||
|
|
||
| auto max_it = std::ranges::max_element( | ||
| id_to_field.get(), | ||
| [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); | ||
|
|
||
| return max_it->first; | ||
| } | ||
|
|
||
| Result<std::unique_ptr<StructLikeAccessor>> Schema::GetAccessorById( | ||
| int32_t field_id) const { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto id_to_position_path, id_to_position_path_.Get(*this)); | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we need to add the Java cc @WZhuo
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is equivalent to java's checkCompatibility, which only checks types and default values. |
||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add an extra parameter
case_sensitive?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, Java impl also has
checkForRedundantPartitions, do we want to add that check? We can add a TODO somewhere if necessary.