-
Notifications
You must be signed in to change notification settings - Fork 405
Write Deletion Vectors #2822
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
Open
rambleraptor
wants to merge
3
commits into
apache:main
Choose a base branch
from
rambleraptor:deletion_vector_write
base: main
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.
+203
−1
Open
Write Deletion Vectors #2822
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| import pytest | ||
| from pyroaring import BitMap | ||
|
|
||
| from pyiceberg.table.puffin import _deserialize_bitmap | ||
| from pyiceberg.table.puffin import PROPERTY_REFERENCED_DATA_FILE, PuffinFile, PuffinWriter, _deserialize_bitmap | ||
|
|
||
|
|
||
| def _open_file(file: str) -> bytes: | ||
|
|
@@ -71,3 +71,78 @@ def test_map_high_vals() -> None: | |
|
|
||
| with pytest.raises(ValueError, match="Key 4022190063 is too large, max 2147483647 to maintain compatibility with Java impl"): | ||
| _ = _deserialize_bitmap(puffin) | ||
|
|
||
|
|
||
| def test_puffin_round_trip() -> None: | ||
| # Define some deletion positions for multiple files | ||
| deletions1 = [10, 20, 30] | ||
|
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. Iceberg deletion vectors expect 1:1 for DV:path. The current PuffinWriter may violate the expectation. For instance, the following code writes 2 blobs without merging them. Do you fix this behavior as a follow-up, or the caller should provide the merged DV? deletions1a = [10, 20]
deletions1b = [30]
...
writer.add(positions=deletions1a, referenced_data_file=file1_path)
writer.add(positions=deletions1b, referenced_data_file=file1_path) |
||
| deletions2 = [5, (1 << 32) + 1] # Test with a high-bit position | ||
|
|
||
| file1_path = "path/to/data1.parquet" | ||
| file2_path = "path/to/data2.parquet" | ||
|
|
||
| # Write the Puffin file | ||
| writer = PuffinWriter() | ||
| writer.add(positions=deletions1, referenced_data_file=file1_path) | ||
| writer.add(positions=deletions2, referenced_data_file=file2_path) | ||
| puffin_bytes = writer.finish() | ||
|
|
||
| # Read the Puffin file back | ||
| reader = PuffinFile(puffin_bytes) | ||
|
|
||
| # Assert footer metadata | ||
| assert len(reader.footer.blobs) == 2 | ||
|
|
||
| blob1_meta = reader.footer.blobs[0] | ||
| assert blob1_meta.properties[PROPERTY_REFERENCED_DATA_FILE] == file1_path | ||
| assert blob1_meta.properties["cardinality"] == str(len(deletions1)) | ||
|
|
||
| blob2_meta = reader.footer.blobs[1] | ||
| assert blob2_meta.properties[PROPERTY_REFERENCED_DATA_FILE] == file2_path | ||
| assert blob2_meta.properties["cardinality"] == str(len(deletions2)) | ||
|
|
||
| # Assert the content of deletion vectors | ||
| read_vectors = reader.to_vector() | ||
|
|
||
| assert file1_path in read_vectors | ||
| assert file2_path in read_vectors | ||
|
|
||
| assert read_vectors[file1_path].to_pylist() == sorted(deletions1) | ||
| assert read_vectors[file2_path].to_pylist() == sorted(deletions2) | ||
|
|
||
|
|
||
| def test_write_and_read_puffin_file() -> None: | ||
| writer = PuffinWriter() | ||
| writer.add(positions=[1, 2, 3], referenced_data_file="file1.parquet") | ||
| writer.add(positions=[4, 5, 6], referenced_data_file="file2.parquet") | ||
| puffin_bytes = writer.finish() | ||
|
|
||
| reader = PuffinFile(puffin_bytes) | ||
|
|
||
| assert len(reader.footer.blobs) == 2 | ||
| blob1 = reader.footer.blobs[0] | ||
| blob2 = reader.footer.blobs[1] | ||
|
|
||
| assert blob1.properties["referenced-data-file"] == "file1.parquet" | ||
| assert blob1.properties["cardinality"] == "3" | ||
| assert blob1.type == "deletion-vector-v1" | ||
| assert blob1.snapshot_id == -1 | ||
| assert blob1.sequence_number == -1 | ||
| assert blob1.compression_codec is None | ||
|
|
||
| assert blob2.properties["referenced-data-file"] == "file2.parquet" | ||
| assert blob2.properties["cardinality"] == "3" | ||
|
|
||
| vectors = reader.to_vector() | ||
| assert len(vectors) == 2 | ||
| assert vectors["file1.parquet"].to_pylist() == [1, 2, 3] | ||
| assert vectors["file2.parquet"].to_pylist() == [4, 5, 6] | ||
|
|
||
|
|
||
| def test_puffin_file_with_no_blobs() -> None: | ||
| writer = PuffinWriter() | ||
| puffin_bytes = writer.finish() | ||
|
|
||
| reader = PuffinFile(puffin_bytes) | ||
| assert len(reader.footer.blobs) == 0 | ||
| assert len(reader.to_vector()) == 0 | ||
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.
Iceberg spec recommends writing
created-byproperty in Puffin files: https://iceberg.apache.org/puffin-spec/#deletion-vector-v1-blob-type. Could you please write the property?