-
Notifications
You must be signed in to change notification settings - Fork 3k
API: Access deleted and added delete files in Snapshot #5105
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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| package org.apache.iceberg; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -28,6 +29,7 @@ | |
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Objects; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Iterables; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
|
|
@@ -54,8 +56,10 @@ class BaseSnapshot implements Snapshot { | |
| private transient List<ManifestFile> allManifests = null; | ||
| private transient List<ManifestFile> dataManifests = null; | ||
| private transient List<ManifestFile> deleteManifests = null; | ||
| private transient List<DataFile> cachedAdds = null; | ||
| private transient List<DataFile> cachedDeletes = null; | ||
| private transient List<DataFile> addedDataFiles = null; | ||
| private transient List<DataFile> removedDataFiles = null; | ||
| private transient List<DeleteFile> addedDeleteFiles = null; | ||
| private transient List<DeleteFile> removedDeleteFiles = null; | ||
|
|
||
| /** | ||
| * For testing only. | ||
|
|
@@ -235,55 +239,101 @@ public List<ManifestFile> deleteManifests() { | |
| } | ||
|
|
||
| @Override | ||
| public List<DataFile> addedFiles(FileIO fileIO) { | ||
| if (cachedAdds == null) { | ||
| cacheChanges(fileIO); | ||
| public List<DataFile> addedDataFiles(FileIO fileIO) { | ||
| if (addedDataFiles == null) { | ||
| cacheDataFileChanges(fileIO); | ||
| } | ||
| return cachedAdds; | ||
| return addedDataFiles; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated since 0.14.0, will be removed in 1.0.0; Use {@link Snapshot#addedFiles(FileIO)} instead. | ||
| * @deprecated since 0.14.0, will be removed in 1.0.0; Use {@link Snapshot#addedDataFiles(FileIO)} instead. | ||
| */ | ||
| @Override | ||
| @Deprecated | ||
| public List<DataFile> addedFiles() { | ||
| if (cachedAdds == null) { | ||
| cacheChanges(io); | ||
| if (addedDataFiles == null) { | ||
| cacheDataFileChanges(io); | ||
| } | ||
| return cachedAdds; | ||
| return addedDataFiles; | ||
| } | ||
|
|
||
| @Override | ||
| public List<DataFile> deletedFiles(FileIO fileIO) { | ||
| if (cachedDeletes == null) { | ||
| cacheChanges(fileIO); | ||
| public List<DataFile> removedDataFiles(FileIO fileIO) { | ||
| if (removedDataFiles == null) { | ||
| cacheDataFileChanges(fileIO); | ||
| } | ||
| return cachedDeletes; | ||
| return removedDataFiles; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated since 0.14.0, will be removed in 1.0.0; Use {@link Snapshot#deletedFiles(FileIO)} instead. | ||
| * @deprecated since 0.14.0, will be removed in 1.0.0; Use {@link Snapshot#removedDataFiles(FileIO)} instead. | ||
| */ | ||
| @Override | ||
| @Deprecated | ||
| public List<DataFile> deletedFiles() { | ||
| if (cachedDeletes == null) { | ||
| cacheChanges(io); | ||
| if (removedDataFiles == null) { | ||
| cacheDataFileChanges(io); | ||
| } | ||
| return cachedDeletes; | ||
| return removedDataFiles; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<DeleteFile> addedDeleteFiles(FileIO fileIO) { | ||
| if (addedDeleteFiles == null) { | ||
| cacheDeleteFileChanges(fileIO); | ||
| } | ||
| return addedDeleteFiles; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<DeleteFile> removedDeleteFiles(FileIO fileIO) { | ||
| if (removedDeleteFiles == null) { | ||
| cacheDeleteFileChanges(fileIO); | ||
| } | ||
| return removedDeleteFiles; | ||
| } | ||
|
|
||
| @Override | ||
| public String manifestListLocation() { | ||
| return manifestListLocation; | ||
| } | ||
|
|
||
| private void cacheChanges(FileIO fileIO) { | ||
| if (fileIO == null) { | ||
| throw new IllegalArgumentException("Cannot cache changes: FileIO is null"); | ||
| private void cacheDeleteFileChanges(FileIO fileIO) { | ||
| Preconditions.checkArgument(fileIO != null, "Cannot cache delete file changes: FileIO is null"); | ||
|
|
||
| ImmutableList.Builder<DeleteFile> adds = ImmutableList.builder(); | ||
| ImmutableList.Builder<DeleteFile> deletes = ImmutableList.builder(); | ||
|
|
||
| Iterable<ManifestFile> changedManifests = Iterables.filter(deleteManifests(fileIO), | ||
| manifest -> Objects.equal(manifest.snapshotId(), snapshotId)); | ||
|
|
||
| for (ManifestFile manifest : changedManifests) { | ||
| try (ManifestReader<DeleteFile> reader = ManifestFiles.readDeleteManifest(manifest, fileIO, null)) { | ||
|
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. Warning: the spec map is null. If I remember correctly, |
||
| for (ManifestEntry<DeleteFile> entry : reader.entries()) { | ||
| switch (entry.status()) { | ||
| case ADDED: | ||
| adds.add(entry.file().copy()); | ||
| break; | ||
| case DELETED: | ||
| deletes.add(entry.file().copyWithoutStats()); | ||
| break; | ||
| default: | ||
| // ignore existing | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to close manifest reader", e); | ||
| } | ||
| } | ||
|
|
||
| this.addedDeleteFiles = adds.build(); | ||
| this.removedDeleteFiles = deletes.build(); | ||
| } | ||
|
|
||
| private void cacheDataFileChanges(FileIO fileIO) { | ||
| Preconditions.checkArgument(fileIO != null, "Cannot cache data file changes: FileIO is null"); | ||
|
|
||
| ImmutableList.Builder<DataFile> adds = ImmutableList.builder(); | ||
| ImmutableList.Builder<DataFile> deletes = ImmutableList.builder(); | ||
|
|
||
|
|
@@ -310,8 +360,8 @@ private void cacheChanges(FileIO fileIO) { | |
| throw new RuntimeIOException(e, "Failed to close entries while caching changes"); | ||
| } | ||
|
|
||
| this.cachedAdds = adds.build(); | ||
| this.cachedDeletes = deletes.build(); | ||
| this.addedDataFiles = adds.build(); | ||
| this.removedDataFiles = deletes.build(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
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.
Renamed methods haven't been released yet so we won't break anyone.