-
Notifications
You must be signed in to change notification settings - Fork 736
awong/iceberg v2/equality deletes #30204
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
Draft
andrwng
wants to merge
5
commits into
dev
Choose a base branch
from
awong/iceberg-v2/equality-deletes
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c696dce
iceberg: add equality delete file writer
andrwng bd0c55d
iceberg: extract shared manifest utilities from merge_append
andrwng 481c8cb
iceberg: add delete-related snapshot summary fields
andrwng 8edd6fd
iceberg: add row_delta_action for atomic data + delete commits
andrwng 9df7cb3
iceberg: add row_delta to transaction API
andrwng 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
Some comments aren't visible on the classic Files Changed page.
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,50 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Licensed as a Redpanda Enterprise file under the Redpanda Community | ||
| * License (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md | ||
| */ | ||
|
|
||
| #include "iceberg/equality_delete_file.h" | ||
|
|
||
| #include "bytes/iostream.h" | ||
| #include "serde/parquet/writer.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| ss::future<delete_file_result> write_equality_delete_file( | ||
| equality_delete_options opts, | ||
| chunked_vector<serde::parquet::group_value> rows) { | ||
| iobuf file; | ||
| serde::parquet::writer w( | ||
| {.schema = std::move(opts.parquet_schema), .compress = opts.compress}, | ||
| make_iobuf_ref_output_stream(file)); | ||
|
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 is another test. |
||
| co_await w.init(); | ||
|
|
||
| auto record_count = rows.size(); | ||
| for (auto& row : rows) { | ||
| co_await w.write_row(std::move(row)); | ||
| } | ||
|
|
||
| co_await w.close(); | ||
|
|
||
| data_file df{ | ||
| .content_type = data_file_content_type::equality_deletes, | ||
| .file_path = uri{}, | ||
| .file_format = data_file_format::parquet, | ||
| .partition = partition_key{}, | ||
| .record_count = record_count, | ||
| .file_size_bytes = file.size_bytes(), | ||
| .equality_ids = std::move(opts.equality_field_ids), | ||
| }; | ||
|
|
||
| co_return delete_file_result{ | ||
| .file_data = std::move(file), | ||
| .manifest_entry = std::move(df), | ||
| }; | ||
| } | ||
|
|
||
| } // 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,44 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Licensed as a Redpanda Enterprise file under the Redpanda Community | ||
| * License (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include "bytes/iobuf.h" | ||
| #include "container/chunked_vector.h" | ||
| #include "iceberg/datatypes.h" | ||
| #include "iceberg/manifest_entry.h" | ||
| #include "serde/parquet/schema.h" | ||
| #include "serde/parquet/value.h" | ||
|
|
||
| #include <seastar/core/future.hh> | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| struct delete_file_result { | ||
|
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. Spill to disk? |
||
| iobuf file_data; | ||
| data_file manifest_entry; | ||
| }; | ||
|
|
||
| struct equality_delete_options { | ||
| serde::parquet::schema_element parquet_schema; | ||
| chunked_vector<nested_field::id_t> equality_field_ids; | ||
| bool compress = false; | ||
| }; | ||
|
|
||
| /// \brief Write an equality delete file in parquet format from key column | ||
| /// values. | ||
| /// | ||
| /// The schema must match the equality columns from the table schema. The | ||
| /// resulting data_file has content_type=equality_deletes and equality_ids | ||
| /// populated from the provided field IDs. | ||
| ss::future<delete_file_result> write_equality_delete_file( | ||
| equality_delete_options opts, | ||
| chunked_vector<serde::parquet::group_value> rows); | ||
|
|
||
| } // 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,134 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Licensed as a Redpanda Enterprise file under the Redpanda Community | ||
| * License (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md | ||
| */ | ||
|
|
||
| #include "iceberg/equality_delete_file.h" | ||
| #include "serde/parquet/reader.h" | ||
| #include "serde/parquet/value.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| namespace { | ||
|
|
||
| serde::parquet::schema_element two_column_key_schema() { | ||
| using serde::parquet::byte_array_type; | ||
| using serde::parquet::field_repetition_type; | ||
| using serde::parquet::i32_type; | ||
| using serde::parquet::schema_element; | ||
| using serde::parquet::string_type; | ||
|
|
||
| chunked_vector<schema_element> children; | ||
| children.push_back( | ||
| schema_element{ | ||
| .type = i32_type{}, | ||
| .repetition_type = field_repetition_type::required, | ||
| .path = {ss::sstring("id")}, | ||
| .field_id = 1, | ||
| }); | ||
| children.push_back( | ||
| schema_element{ | ||
| .type = byte_array_type{}, | ||
| .repetition_type = field_repetition_type::required, | ||
| .path = {ss::sstring("name")}, | ||
| .field_id = 2, | ||
| .logical_type = string_type{}, | ||
| }); | ||
| return schema_element{ | ||
| .type = std::monostate{}, | ||
| .repetition_type = field_repetition_type::required, | ||
| .path = {ss::sstring("equality_deletes")}, | ||
| .children = std::move(children), | ||
| }; | ||
| } | ||
|
|
||
| serde::parquet::group_value make_row(int32_t id, const ss::sstring& name) { | ||
| serde::parquet::group_value row; | ||
| row.push_back( | ||
| serde::parquet::group_member{serde::parquet::int32_value{id}}); | ||
| row.push_back( | ||
| serde::parquet::group_member{ | ||
| serde::parquet::byte_array_value{iobuf::from(name)}}); | ||
| return row; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // NOLINTBEGIN(*magic-number*) | ||
|
|
||
| TEST(EqualityDeleteFile, RoundTrip) { | ||
| chunked_vector<serde::parquet::group_value> rows; | ||
| rows.push_back(make_row(1, "alice")); | ||
| rows.push_back(make_row(2, "bob")); | ||
| rows.push_back(make_row(3, "charlie")); | ||
|
|
||
| chunked_vector<nested_field::id_t> field_ids; | ||
| field_ids.push_back(nested_field::id_t{1}); | ||
| field_ids.push_back(nested_field::id_t{2}); | ||
|
|
||
| equality_delete_options opts{ | ||
| .parquet_schema = two_column_key_schema(), | ||
| .equality_field_ids = std::move(field_ids), | ||
| }; | ||
|
|
||
| auto result | ||
| = write_equality_delete_file(std::move(opts), std::move(rows)).get(); | ||
|
|
||
| EXPECT_EQ( | ||
| result.manifest_entry.content_type, | ||
| data_file_content_type::equality_deletes); | ||
| EXPECT_EQ(result.manifest_entry.file_format, data_file_format::parquet); | ||
| EXPECT_EQ(result.manifest_entry.record_count, 3); | ||
| EXPECT_GT(result.manifest_entry.file_size_bytes, 0); | ||
|
|
||
| ASSERT_TRUE(result.manifest_entry.equality_ids.has_value()); | ||
| auto& eq_ids = result.manifest_entry.equality_ids.value(); | ||
| ASSERT_EQ(eq_ids.size(), 2); | ||
| EXPECT_EQ(eq_ids[0], nested_field::id_t{1}); | ||
| EXPECT_EQ(eq_ids[1], nested_field::id_t{2}); | ||
|
|
||
| auto records | ||
| = serde::parquet::read_file_as_records(std::move(result.file_data)).get(); | ||
|
|
||
| ASSERT_EQ(records.size(), 3); | ||
| EXPECT_EQ(records[0], make_row(1, "alice")); | ||
| EXPECT_EQ(records[1], make_row(2, "bob")); | ||
| EXPECT_EQ(records[2], make_row(3, "charlie")); | ||
| } | ||
|
|
||
| TEST(EqualityDeleteFile, RoundTripCompressed) { | ||
| chunked_vector<serde::parquet::group_value> rows; | ||
| rows.push_back(make_row(42, "eve")); | ||
|
|
||
| chunked_vector<nested_field::id_t> field_ids; | ||
| field_ids.push_back(nested_field::id_t{1}); | ||
| field_ids.push_back(nested_field::id_t{2}); | ||
|
|
||
| equality_delete_options opts{ | ||
| .parquet_schema = two_column_key_schema(), | ||
| .equality_field_ids = std::move(field_ids), | ||
| .compress = true, | ||
| }; | ||
|
|
||
| auto result | ||
| = write_equality_delete_file(std::move(opts), std::move(rows)).get(); | ||
|
|
||
| EXPECT_EQ(result.manifest_entry.record_count, 1); | ||
|
|
||
| auto records | ||
| = serde::parquet::read_file_as_records(std::move(result.file_data)).get(); | ||
|
|
||
| ASSERT_EQ(records.size(), 1); | ||
| EXPECT_EQ(records[0], make_row(42, "eve")); | ||
| } | ||
|
|
||
| // NOLINTEND(*magic-number*) | ||
|
|
||
| } // namespace iceberg |
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.
This is a test