Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected void refreshFromMetadataLocation(String newLocation, int numRetries) {
protected void refreshFromMetadataLocation(String newLocation, Predicate<Exception> shouldRetry,
int numRetries) {
refreshFromMetadataLocation(newLocation, shouldRetry, numRetries,
metadataLocation -> TableMetadataParser.read(io(), metadataLocation));
metadataLocation -> TableMetadata.buildFromLocation(io(), metadataLocation).build());
Copy link
Contributor Author

@amogh-jahagirdar amogh-jahagirdar Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know about this, here we parse the metadata and then again copy over the structures in the builder. But ultimately when we read, we need to go through a single point in the builder for setting main if it doesn't exist and there is a current snapshot. I don't think just setting the ref when parsing would work because ultimately it needs to be encapsulated in an metadata update even for operations which don't produce snapshots. @rdblue thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should change the metadata after reading it, so it is probably best to fix this up in the TableMetadata constructor rather than in the builder, which is used to produce new TableMetadata objects.

}

protected void refreshFromMetadataLocation(String newLocation, Predicate<Exception> shouldRetry,
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/apache/iceberg/TableMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.iceberg.exceptions.ValidationException;
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;
Expand Down Expand Up @@ -755,6 +756,10 @@ public static Builder buildFrom(TableMetadata base) {
return new Builder(base);
}

static Builder buildFromLocation(FileIO io, String location) {
return buildFrom(TableMetadataParser.read(io, location));
}

public static class Builder {
private static final int LAST_ADDED = -1;

Expand Down Expand Up @@ -1165,6 +1170,11 @@ private boolean hasChanges() {
}

public TableMetadata build() {
if (refs.isEmpty() && currentSnapshotId != -1) {
SnapshotRef main = SnapshotRef.branchBuilder(currentSnapshotId).build();
setRef(SnapshotRef.MAIN_BRANCH, main);
}

if (!hasChanges()) {
return base;
}
Expand Down