-
Notifications
You must be signed in to change notification settings - Fork 116
feat: MergingSnapshotUpdate merges multiple DVs #708
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
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * 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/data/puffin_dv_register.h" | ||
|
|
||
| #include <optional> | ||
| #include <string_view> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/data/deletion_vector_writer.h" | ||
| #include "iceberg/data/dv_util_internal.h" | ||
| #include "iceberg/deletes/position_delete_index.h" | ||
| #include "iceberg/manifest/manifest_entry.h" | ||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg { | ||
| namespace { | ||
|
|
||
| class DataPuffinDVIO final : public PuffinDVIO { | ||
| public: | ||
| Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs( | ||
| std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path, | ||
| const std::shared_ptr<FileIO>& io) override { | ||
| if (groups.empty()) { | ||
| return std::vector<std::shared_ptr<DataFile>>{}; | ||
| } | ||
|
|
||
| ICEBERG_ASSIGN_OR_RAISE( | ||
| auto writer, | ||
| DeletionVectorWriter::Make(DeletionVectorWriterOptions{ | ||
| .path = std::string(output_path), | ||
| .io = io, | ||
| .load_previous_deletes = [](std::string_view) | ||
| -> Result<std::optional<PositionDeleteIndex>> { return std::nullopt; }})); | ||
|
|
||
| for (const auto& group : groups) { | ||
| PositionDeleteIndex merged; | ||
| for (const auto& delete_file : group.delete_files) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto index, DVUtil::ReadDV(delete_file, io)); | ||
| merged.Merge(index); | ||
| } | ||
| ICEBERG_RETURN_UNEXPECTED(writer->Delete(group.referenced_data_file, merged, | ||
| group.spec, group.partition)); | ||
| } | ||
|
|
||
| ICEBERG_RETURN_UNEXPECTED(writer->Close()); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto metadata, writer->Metadata()); | ||
| return std::move(metadata.data_files); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| std::shared_ptr<PuffinDVIO> MakePuffinDVIO() { | ||
| return std::make_shared<DataPuffinDVIO>(); | ||
| } | ||
|
|
||
| void RegisterPuffinDVIO() { | ||
| static PuffinDVIORegistry registry( | ||
| []() -> Result<std::shared_ptr<PuffinDVIO>> { return MakePuffinDVIO(); }); | ||
| } | ||
|
|
||
| } // 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,36 @@ | ||
| /* | ||
| * 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/data/puffin_dv_register.h | ||
| /// Puffin deletion vector I/O registration. | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "iceberg/iceberg_data_export.h" | ||
| #include "iceberg/puffin_dv_io.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| ICEBERG_DATA_EXPORT std::shared_ptr<PuffinDVIO> MakePuffinDVIO(); | ||
|
|
||
| ICEBERG_DATA_EXPORT void RegisterPuffinDVIO(); | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * 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/puffin_dv_io.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg { | ||
| namespace { | ||
|
|
||
| PuffinDVIOFactory GetNotImplementedFactory() { | ||
| return []() -> Result<std::shared_ptr<PuffinDVIO>> { | ||
| return NotImplemented("Missing Puffin DV I/O factory"); | ||
| }; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| PuffinDVIO::~PuffinDVIO() = default; | ||
|
|
||
| PuffinDVIORegistry::PuffinDVIORegistry(PuffinDVIOFactory factory) { | ||
| GetFactory() = std::move(factory); | ||
| } | ||
|
|
||
| PuffinDVIOFactory& PuffinDVIORegistry::GetFactory() { | ||
| static auto* factory = new PuffinDVIOFactory(GetNotImplementedFactory()); | ||
| return *factory; | ||
| } | ||
|
|
||
| Result<std::vector<std::shared_ptr<DataFile>>> PuffinDVIORegistry::MergeAndWriteDVs( | ||
| std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path, | ||
| const std::shared_ptr<FileIO>& io) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto dv_io, GetFactory()()); | ||
| ICEBERG_PRECHECK(dv_io != nullptr, "Puffin DV I/O factory returned null"); | ||
| return dv_io->MergeAndWriteDVs(groups, output_path, io); | ||
| } | ||
|
|
||
| } // 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,67 @@ | ||
| /* | ||
| * 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/puffin_dv_io.h | ||
| /// Deletion vector merge hooks. | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <span> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/row/partition_values.h" | ||
| #include "iceberg/type_fwd.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| struct ICEBERG_EXPORT DeletionVectorMergeGroup { | ||
| std::string referenced_data_file; | ||
| std::vector<std::shared_ptr<DataFile>> delete_files; | ||
| std::shared_ptr<PartitionSpec> spec; | ||
| PartitionValues partition; | ||
| }; | ||
|
|
||
| class ICEBERG_EXPORT PuffinDVIO { | ||
| public: | ||
| virtual ~PuffinDVIO(); | ||
|
|
||
| virtual Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs( | ||
| std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path, | ||
| const std::shared_ptr<FileIO>& io) = 0; | ||
| }; | ||
|
|
||
| using PuffinDVIOFactory = std::function<Result<std::shared_ptr<PuffinDVIO>>()>; | ||
|
|
||
| struct ICEBERG_EXPORT PuffinDVIORegistry { | ||
| explicit PuffinDVIORegistry(PuffinDVIOFactory factory); | ||
|
|
||
| static PuffinDVIOFactory& GetFactory(); | ||
|
|
||
| static Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs( | ||
| std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path, | ||
| const std::shared_ptr<FileIO>& io); | ||
| }; | ||
|
|
||
| } // namespace iceberg |
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.
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.
#820 has been reverted via this change because it does not add too much value but a lot of noise. cc @yadavay-amzn @zhjwpku