-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add fields for $files table delete file deduplication #28933
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
kaveti
wants to merge
2
commits into
trinodb:master
Choose a base branch
from
kaveti:files-table-dedup
base: master
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.
Open
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
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
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 |
|---|---|---|
|
|
@@ -431,6 +431,87 @@ public void testFilesTable() | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testFilesTableDeleteFileDeduplication() | ||
|
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. Could you add the test in v3? |
||
| throws Exception | ||
| { | ||
| try (TestTable testTable = newTrinoTable("test_files_delete_dedup_", | ||
| "WITH (partitioning = ARRAY['regionkey']) AS SELECT * FROM tpch.tiny.nation")) { | ||
| String tableName = testTable.getName(); | ||
| Table icebergTable = loadTable(tableName); | ||
|
|
||
| // Verify initial state: only data files, no delete files | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 0")) | ||
| .matches("VALUES BIGINT '5'"); // one data file per regionkey partition | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content != 0")) | ||
| .matches("VALUES BIGINT '0'"); | ||
|
|
||
| // Write a position delete via MOR path | ||
| assertUpdate("DELETE FROM " + tableName + " WHERE nationkey = 7", 1); | ||
|
|
||
| // Write an equality delete file for regionkey=2 | ||
| writeEqualityDeleteForTable(icebergTable, fileSystemFactory, | ||
| Optional.of(icebergTable.spec()), | ||
| Optional.of(new PartitionData(new Long[] {2L})), | ||
| ImmutableMap.of("regionkey", 2L), | ||
| Optional.empty()); | ||
|
|
||
| // Verify: each file path should appear exactly once (no duplicates) | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 1")) | ||
| .matches("VALUES BIGINT '1'"); // exactly 1 position delete file | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 2")) | ||
| .matches("VALUES BIGINT '1'"); // exactly 1 equality delete file | ||
|
|
||
| // Verify no duplicate file paths exist | ||
| assertThat(query("SELECT count(file_path) - count(DISTINCT file_path) FROM \"" + tableName + "$files\"")) | ||
| .matches("VALUES BIGINT '0'"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testFilesTableDeletionVectors() | ||
| { | ||
| try (TestTable testTable = newTrinoTable("test_files_dv_", | ||
| "(id INTEGER) WITH (format_version = 3, format = 'PARQUET')")) { | ||
| String tableName = testTable.getName(); | ||
|
|
||
| // Insert data across multiple data files | ||
| for (int i = 0; i < 3; i++) { | ||
| assertUpdate("INSERT INTO " + tableName + " SELECT x FROM UNNEST(sequence(%s, %s)) t(x)".formatted(i * 100 + 1, (i + 1) * 100), 100); | ||
| } | ||
|
|
||
| // Verify initial state: 3 data files, no delete files | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 0")) | ||
| .matches("VALUES BIGINT '3'"); | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content != 0")) | ||
| .matches("VALUES BIGINT '0'"); | ||
|
|
||
| // Delete rows to create deletion vectors (stored in shared Puffin files) | ||
| assertUpdate("DELETE FROM " + tableName + " WHERE id % 2 = 0", 150); | ||
|
|
||
| // In v3, deletion vectors for multiple data files are stored in a single Puffin file. | ||
| // The $files table shows one entry per DV (one per data file), all sharing the same file_path. | ||
| // content_offset and content_size_in_bytes distinguish individual DVs within the shared Puffin file. | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 1")) | ||
| .matches("VALUES BIGINT '3'"); // one DV entry per data file | ||
| assertThat(query("SELECT count_if(file_format = 'PUFFIN') FROM \"" + tableName + "$files\" WHERE content = 1")) | ||
| .matches("VALUES BIGINT '3'"); | ||
| // All DV entries share the same Puffin file path | ||
| assertThat(query("SELECT count(DISTINCT file_path) FROM \"" + tableName + "$files\" WHERE content = 1")) | ||
| .matches("VALUES BIGINT '1'"); | ||
|
|
||
| // Each DV entry has distinct content_offset within the shared Puffin file | ||
| assertThat(query("SELECT count(DISTINCT content_offset) FROM \"" + tableName + "$files\" WHERE content = 1")) | ||
| .matches("VALUES BIGINT '3'"); | ||
| // All DV entries have non-null content_offset and content_size_in_bytes | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 1 AND content_offset IS NOT NULL AND content_size_in_bytes IS NOT NULL")) | ||
| .matches("VALUES BIGINT '3'"); | ||
| // Data files have null content_offset and content_size_in_bytes | ||
| assertThat(query("SELECT count(*) FROM \"" + tableName + "$files\" WHERE content = 0 AND content_offset IS NULL AND content_size_in_bytes IS NULL")) | ||
| .matches("VALUES BIGINT '3'"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testFilesPartitionTable() | ||
| { | ||
|
|
@@ -452,6 +533,8 @@ public void testFilesPartitionTable() | |
| "('split_offsets', 'array(bigint)', '', '')," + | ||
| "('equality_ids', 'array(integer)', '', '')," + | ||
| "('sort_order_id', 'integer', '', '')," + | ||
| "('content_offset', 'bigint', '', '')," + | ||
| "('content_size_in_bytes', 'bigint', '', '')," + | ||
| "('readable_metrics', 'json', '', '')"); | ||
| assertQuerySucceeds("SELECT * FROM test_schema.\"test_table$files\""); | ||
|
|
||
|
|
||
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
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.
Please update
$filessection in iceberg.md.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.
done @ebyhr