-
Notifications
You must be signed in to change notification settings - Fork 70
feat: implement manifest entry metadata inheritance #178
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5dfb606
fix: implement manifest entry metadata inheritance system
HeartLinked a4cecb4
fix: add explicit keyword and update method calls
HeartLinked 6547316
fix
HeartLinked cb617b5
fix: update method name in manifest_list_reader_test.cc
HeartLinked 7ef7aa4
remove file
HeartLinked d7b8a85
fix review
HeartLinked 0d38fd0
fix review
HeartLinked bc8d106
add test
HeartLinked 845cb61
add test
HeartLinked 59360cc
fix review1
HeartLinked a865704
modify test
HeartLinked 48f34b9
fix review
HeartLinked fd8d225
v1
HeartLinked 84d62bd
v1
HeartLinked 82fe891
fmt
HeartLinked 2de3512
fix review
HeartLinked File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/inheritable_metadata.h" | ||
|
|
||
| #include <cassert> | ||
| #include <utility> | ||
|
|
||
| #include <iceberg/result.h> | ||
|
|
||
| #include "iceberg/manifest_entry.h" | ||
| #include "iceberg/manifest_list.h" | ||
| #include "iceberg/snapshot.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| BaseInheritableMetadata::BaseInheritableMetadata(int32_t spec_id, int64_t snapshot_id, | ||
| int64_t sequence_number, | ||
| std::string manifest_location) | ||
| : spec_id_(spec_id), | ||
| snapshot_id_(snapshot_id), | ||
| sequence_number_(sequence_number), | ||
| manifest_location_(std::move(manifest_location)) {} | ||
|
|
||
| Status BaseInheritableMetadata::Apply(ManifestEntry& entry) { | ||
| if (!entry.snapshot_id.has_value()) { | ||
| entry.snapshot_id = snapshot_id_; | ||
| } | ||
|
|
||
| // In v1 metadata, the data sequence number is not persisted and can be safely defaulted | ||
| // to 0. | ||
| // In v2 metadata, the data sequence number should be inherited iff the entry status | ||
| // is ADDED. | ||
| if (!entry.sequence_number.has_value() && | ||
| (sequence_number_ == 0 || entry.status == ManifestStatus::kAdded)) { | ||
| entry.sequence_number = sequence_number_; | ||
| } | ||
|
|
||
| // In v1 metadata, the file sequence number is not persisted and can be safely defaulted | ||
| // to 0. | ||
| // In v2 metadata, the file sequence number should be inherited iff the entry status | ||
| // is ADDED. | ||
| if (!entry.file_sequence_number.has_value() && | ||
| (sequence_number_ == 0 || entry.status == ManifestStatus::kAdded)) { | ||
| entry.file_sequence_number = sequence_number_; | ||
| } | ||
|
|
||
| if (entry.data_file) { | ||
HeartLinked marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| entry.data_file->partition_spec_id = spec_id_; | ||
| } else { | ||
| return InvalidManifest("Manifest entry has no data file"); | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| Status EmptyInheritableMetadata::Apply(ManifestEntry& entry) { | ||
| if (!entry.snapshot_id.has_value()) { | ||
| return InvalidManifest( | ||
| "Entries must have explicit snapshot ids if inherited metadata is empty"); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| CopyInheritableMetadata::CopyInheritableMetadata(int64_t snapshot_id) | ||
| : snapshot_id_(snapshot_id) {} | ||
|
|
||
| Status CopyInheritableMetadata::Apply(ManifestEntry& entry) { | ||
| entry.snapshot_id = snapshot_id_; | ||
| return {}; | ||
| } | ||
|
|
||
| Result<std::unique_ptr<InheritableMetadata>> InheritableMetadataFactory::Empty() { | ||
| return std::make_unique<EmptyInheritableMetadata>(); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<InheritableMetadata>> InheritableMetadataFactory::FromManifest( | ||
| const ManifestFile& manifest) { | ||
| // Validate that the manifest has a snapshot ID assigned | ||
| if (manifest.added_snapshot_id == Snapshot::kInvalidSnapshotId) { | ||
| return InvalidManifest("Manifest file {} has no snapshot ID", manifest.manifest_path); | ||
| } | ||
|
|
||
| return std::make_unique<BaseInheritableMetadata>( | ||
| manifest.partition_spec_id, manifest.added_snapshot_id, manifest.sequence_number, | ||
| manifest.manifest_path); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<InheritableMetadata>> InheritableMetadataFactory::ForCopy( | ||
| int64_t snapshot_id) { | ||
| return std::make_unique<CopyInheritableMetadata>(snapshot_id); | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /// \file iceberg/inheritable_metadata.h | ||
| /// Metadata inheritance system for manifest entries. | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/type_fwd.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Interface for applying inheritable metadata to manifest entries. | ||
| /// | ||
| /// When manifest entries have null values for certain fields (snapshot id, | ||
| /// data sequence number, file sequence number), these values should be inherited | ||
| /// from the manifest file. This interface provides a way to apply such inheritance rules. | ||
| class ICEBERG_EXPORT InheritableMetadata { | ||
| public: | ||
| virtual ~InheritableMetadata() = default; | ||
|
|
||
| /// \brief Apply inheritable metadata to a manifest entry. | ||
| /// \param entry The manifest entry to modify. | ||
| /// \return Status indicating success or failure. | ||
| virtual Status Apply(ManifestEntry& entry) = 0; | ||
| }; | ||
|
|
||
| /// \brief Base implementation of InheritableMetadata that handles standard inheritance | ||
| /// rules. | ||
| class ICEBERG_EXPORT BaseInheritableMetadata : public InheritableMetadata { | ||
| public: | ||
| /// \brief Constructor for base inheritable metadata. | ||
| /// \param spec_id Partition spec ID from the manifest. | ||
| /// \param snapshot_id Snapshot ID from the manifest. | ||
| /// \param sequence_number Sequence number from the manifest. | ||
| /// \param manifest_location Path to the manifest file. | ||
| BaseInheritableMetadata(int32_t spec_id, int64_t snapshot_id, int64_t sequence_number, | ||
| std::string manifest_location); | ||
|
|
||
| Status Apply(ManifestEntry& entry) override; | ||
|
|
||
| private: | ||
| int32_t spec_id_; | ||
| int64_t snapshot_id_; | ||
| int64_t sequence_number_; | ||
| std::string manifest_location_; | ||
| }; | ||
|
|
||
| /// \brief Empty implementation that applies no inheritance. | ||
| class ICEBERG_EXPORT EmptyInheritableMetadata : public InheritableMetadata { | ||
| public: | ||
| Status Apply(ManifestEntry& entry) override; | ||
| }; | ||
|
|
||
| /// \brief Metadata inheritance for copying manifests before commit. | ||
| class ICEBERG_EXPORT CopyInheritableMetadata : public InheritableMetadata { | ||
| public: | ||
| /// \brief Constructor for copy metadata. | ||
| /// \param snapshot_id The snapshot ID to use for copying. | ||
| explicit CopyInheritableMetadata(int64_t snapshot_id); | ||
|
|
||
| Status Apply(ManifestEntry& entry) override; | ||
|
|
||
| private: | ||
| int64_t snapshot_id_; | ||
| }; | ||
|
|
||
| /// \brief Factory for creating InheritableMetadata instances. | ||
| class ICEBERG_EXPORT InheritableMetadataFactory { | ||
| public: | ||
| /// \brief Create an empty metadata instance that applies no inheritance. | ||
| static Result<std::unique_ptr<InheritableMetadata>> Empty(); | ||
|
|
||
| /// \brief Create metadata instance from a manifest file. | ||
| /// \param manifest The manifest file to extract metadata from. | ||
| /// \return Inheritable metadata based on the manifest. | ||
| static Result<std::unique_ptr<InheritableMetadata>> FromManifest( | ||
| const ManifestFile& manifest); | ||
|
|
||
| /// \brief Create metadata instance for rewriting a manifest before commit. | ||
| /// \param snapshot_id The snapshot ID for the copy operation. | ||
| /// \return Inheritable metadata for copying. | ||
| static Result<std::unique_ptr<InheritableMetadata>> ForCopy(int64_t snapshot_id); | ||
|
|
||
| private: | ||
| InheritableMetadataFactory() = default; | ||
| }; | ||
|
|
||
| } // namespace iceberg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.