Skip to content

Commit

Permalink
More checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
szehon-ho committed Nov 16, 2024
1 parent c1b0838 commit be5d2f5
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public RewriteTablePath rewriteLocationPrefix(String sPrefix, String tPrefix) {
public RewriteTablePath startVersion(String sVersion) {
Preconditions.checkArgument(
sVersion != null && !sVersion.trim().isEmpty(),
"Last copied version('%s') cannot be empty.",
"Start version('%s') cannot be empty.",
sVersion);
this.startVersionName = sVersion;
return this;
Expand Down Expand Up @@ -188,7 +188,8 @@ private void validateAndSetEndVersion() {

if (endVersionName == null) {
LOG.info("No end version specified. Will stage all files to the latest table version.");
Preconditions.checkNotNull(tableMetadata.metadataFileLocation());
Preconditions.checkNotNull(
tableMetadata.metadataFileLocation(), "Metadata file location should not be null");
this.endVersionName = tableMetadata.metadataFileLocation();
} else {
this.endVersionName = validateVersion(tableMetadata, endVersionName);
Expand Down Expand Up @@ -270,7 +271,8 @@ private String rebuildMetadata() {

// rebuild version files
RewriteResult<Snapshot> rewriteVersionResult = rewriteVersionFiles(endMetadata);
Set<Snapshot> diffSnapshots = getDiffSnapshotIds(startMetadata, rewriteVersionResult.toRewrite);
Set<Snapshot> diffSnapshots =
getDiffSnapshotIds(startMetadata, rewriteVersionResult.toRewrite());

Set<String> manifestsToRewrite = manifestsToRewrite(diffSnapshots, startMetadata);
Set<Snapshot> validSnapshots =
Expand All @@ -284,11 +286,11 @@ private String rebuildMetadata() {

// rebuild manifest files
Set<Pair<String, String>> contentFilesToMove =
rewriteManifests(endMetadata, rewriteManifestListResult.toRewrite);
rewriteManifests(endMetadata, rewriteManifestListResult.toRewrite());

Set<Pair<String, String>> movePlan = Sets.newHashSet();
movePlan.addAll(rewriteVersionResult.copyPlan);
movePlan.addAll(rewriteManifestListResult.copyPlan);
movePlan.addAll(rewriteVersionResult.copyPlan());
movePlan.addAll(rewriteManifestListResult.copyPlan());
movePlan.addAll(contentFilesToMove);

return saveFileList(movePlan);
Expand Down Expand Up @@ -326,8 +328,8 @@ private Set<Snapshot> getDiffSnapshotIds(

private RewriteResult<Snapshot> rewriteVersionFiles(TableMetadata endMetadata) {
RewriteResult<Snapshot> result = new RewriteResult<>();
result.toRewrite.addAll(endMetadata.snapshots());
result.copyPlan.add(rewriteVersionFile(endMetadata, endVersionName));
result.toRewrite().addAll(endMetadata.snapshots());
result.copyPlan().add(rewriteVersionFile(endMetadata, endVersionName));

List<MetadataLogEntry> versions = endMetadata.previousFiles();
for (int i = versions.size() - 1; i >= 0; i--) {
Expand All @@ -342,8 +344,8 @@ private RewriteResult<Snapshot> rewriteVersionFiles(TableMetadata endMetadata) {
TableMetadata tableMetadata =
new StaticTableOperations(versionFilePath, table.io()).current();

result.toRewrite.addAll(tableMetadata.snapshots());
result.copyPlan.add(rewriteVersionFile(tableMetadata, versionFilePath));
result.toRewrite().addAll(tableMetadata.snapshots());
result.copyPlan().add(rewriteVersionFile(tableMetadata, versionFilePath));
}

return result;
Expand Down Expand Up @@ -391,12 +393,12 @@ private RewriteResult<ManifestFile> rewriteManifestList(

// return the ManifestFile object for subsequent rewriting
if (manifestsToRewrite.contains(file.path())) {
result.toRewrite.add(file);
result.copyPlan.add(Pair.of(stagingPath(file.path(), stagingDir), newFile.path()));
result.toRewrite().add(file);
result.copyPlan().add(Pair.of(stagingPath(file.path(), stagingDir), newFile.path()));
}
}

result.copyPlan.add(Pair.of(stagingPath, newPath(path, sourcePrefix, targetPrefix)));
result.copyPlan().add(Pair.of(stagingPath, newPath(path, sourcePrefix, targetPrefix)));
return result;
} catch (IOException e) {
throw new UncheckedIOException("Failed to rewrite the manifest list file " + path, e);
Expand Down Expand Up @@ -720,8 +722,8 @@ private String getMetadataLocation(Table tbl) {
}

static class RewriteResult<T> {
Set<T> toRewrite = Sets.newHashSet();
Set<Pair<String, String>> copyPlan = Sets.newHashSet();
private final Set<T> toRewrite = Sets.newHashSet();
private final Set<Pair<String, String>> copyPlan = Sets.newHashSet();

RewriteResult() {}

Expand All @@ -731,5 +733,13 @@ static class RewriteResult<T> {
copyPlan.addAll(r1.copyPlan);
copyPlan.addAll(r2.copyPlan);
}

private Set<T> toRewrite() {
return toRewrite;
}

private Set<Pair<String, String>> copyPlan() {
return copyPlan;
}
}
}
Loading

0 comments on commit be5d2f5

Please sign in to comment.