-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Optimize check for referenced data files in BaseRowDelta #3071
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
|
|
||
| import org.apache.iceberg.ManifestEntry.Status; | ||
| import org.apache.iceberg.exceptions.ValidationException; | ||
| import org.apache.iceberg.expressions.Expression; | ||
| import org.apache.iceberg.expressions.Expressions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Sets; | ||
|
|
@@ -629,4 +630,124 @@ public void testFastAppendDoesNotRemoveStaleDeleteFiles() { | |
| files(FILE_A_DELETES), | ||
| statuses(Status.ADDED)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateDataFilesExistWithConflictDetectionFilter() { | ||
|
Member
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. Should we also add a test where the validation fails? It looks like this one just checks that you can do isolated operations but I think we should do a conflicting test as well.
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. Sure, I'll add one.
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. Added a negative test too. |
||
| // change the spec to be partitioned by data | ||
| table.updateSpec() | ||
| .removeField(Expressions.bucket("data", 16)) | ||
| .addField(Expressions.ref("data")) | ||
| .commit(); | ||
|
|
||
| // add a data file to partition A | ||
| DataFile dataFile1 = DataFiles.builder(table.spec()) | ||
| .withPath("/path/to/data-a.parquet") | ||
| .withFileSizeInBytes(10) | ||
| .withPartitionPath("data=a") | ||
| .withRecordCount(1) | ||
| .build(); | ||
|
|
||
| table.newAppend() | ||
| .appendFile(dataFile1) | ||
| .commit(); | ||
|
|
||
| // add a data file to partition B | ||
| DataFile dataFile2 = DataFiles.builder(table.spec()) | ||
| .withPath("/path/to/data-b.parquet") | ||
| .withFileSizeInBytes(10) | ||
| .withPartitionPath("data=b") | ||
| .withRecordCount(1) | ||
| .build(); | ||
|
|
||
| table.newAppend() | ||
| .appendFile(dataFile2) | ||
| .commit(); | ||
|
|
||
| // use this snapshot as the starting snapshot in rowDelta | ||
| Snapshot baseSnapshot = table.currentSnapshot(); | ||
|
|
||
| // add a delete file for partition A | ||
| DeleteFile deleteFile = FileMetadata.deleteFileBuilder(table.spec()) | ||
| .ofPositionDeletes() | ||
| .withPath("/path/to/data-a-deletes.parquet") | ||
| .withFileSizeInBytes(10) | ||
| .withPartitionPath("data=a") | ||
| .withRecordCount(1) | ||
| .build(); | ||
|
|
||
| Expression conflictDetectionFilter = Expressions.equal("data", "a"); | ||
| RowDelta rowDelta = table.newRowDelta() | ||
| .addDeletes(deleteFile) | ||
| .validateDataFilesExist(ImmutableList.of(dataFile1.path())) | ||
| .validateDeletedFiles() | ||
| .validateFromSnapshot(baseSnapshot.snapshotId()) | ||
| .validateNoConflictingAppends(conflictDetectionFilter); | ||
|
|
||
| // concurrently delete the file for partition B | ||
| table.newDelete() | ||
| .deleteFile(dataFile2) | ||
| .commit(); | ||
|
|
||
| // commit the delta for partition A | ||
| rowDelta.commit(); | ||
|
|
||
| Assert.assertEquals("Table should have one new delete manifest", | ||
| 1, table.currentSnapshot().deleteManifests().size()); | ||
| ManifestFile deletes = table.currentSnapshot().deleteManifests().get(0); | ||
| validateDeleteManifest(deletes, | ||
| seqs(4), | ||
| ids(table.currentSnapshot().snapshotId()), | ||
| files(deleteFile), | ||
| statuses(Status.ADDED)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateDataFilesDoNotExistWithConflictDetectionFilter() { | ||
| // change the spec to be partitioned by data | ||
| table.updateSpec() | ||
| .removeField(Expressions.bucket("data", 16)) | ||
| .addField(Expressions.ref("data")) | ||
| .commit(); | ||
|
|
||
| // add a data file to partition A | ||
| DataFile dataFile1 = DataFiles.builder(table.spec()) | ||
| .withPath("/path/to/data-a.parquet") | ||
| .withFileSizeInBytes(10) | ||
| .withPartitionPath("data=a") | ||
| .withRecordCount(1) | ||
| .build(); | ||
|
|
||
| table.newAppend() | ||
| .appendFile(dataFile1) | ||
| .commit(); | ||
|
|
||
| // use this snapshot as the starting snapshot in rowDelta | ||
| Snapshot baseSnapshot = table.currentSnapshot(); | ||
|
|
||
| // add a delete file for partition A | ||
| DeleteFile deleteFile = FileMetadata.deleteFileBuilder(table.spec()) | ||
| .ofPositionDeletes() | ||
| .withPath("/path/to/data-a-deletes.parquet") | ||
| .withFileSizeInBytes(10) | ||
| .withPartitionPath("data=a") | ||
| .withRecordCount(1) | ||
| .build(); | ||
|
|
||
| Expression conflictDetectionFilter = Expressions.equal("data", "a"); | ||
| RowDelta rowDelta = table.newRowDelta() | ||
| .addDeletes(deleteFile) | ||
| .validateDataFilesExist(ImmutableList.of(dataFile1.path())) | ||
| .validateDeletedFiles() | ||
| .validateFromSnapshot(baseSnapshot.snapshotId()) | ||
| .validateNoConflictingAppends(conflictDetectionFilter); | ||
|
|
||
| // concurrently delete the file for partition A | ||
| table.newDelete() | ||
| .deleteFile(dataFile1) | ||
| .commit(); | ||
|
|
||
| AssertHelpers.assertThrows("Should fail to add deletes because data file is missing", | ||
| ValidationException.class, "Cannot commit, missing data files", | ||
| rowDelta::commit); | ||
| } | ||
| } | ||
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 does make the assumption that the conflict detection filter and referenced data files are related.
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.
I think that is a correct assumption as the conflict detection filter is our scan condition and referenced data files are data files were read.
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.
I think that's a valid assumption.