Skip to content

Commit

Permalink
REST: Assign metadata UUID on create transaction (apache#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanck authored Nov 16, 2022
1 parent b76fff7 commit 6697129
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/MetadataUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String uuid() {

@Override
public void applyTo(TableMetadata.Builder metadataBuilder) {
throw new UnsupportedOperationException("Not implemented");
metadataBuilder.assignUUID(uuid);
}
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/apache/iceberg/TableMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,17 @@ public Builder assignUUID() {
return this;
}

public Builder assignUUID(String newUuid) {
Preconditions.checkArgument(newUuid != null, "Cannot set uuid to null");

if (!newUuid.equals(uuid)) {
this.uuid = newUuid;
changes.add(new MetadataUpdate.AssignUUID(uuid));
}

return this;
}

public Builder upgradeFormatVersion(int newFormatVersion) {
Preconditions.checkArgument(
newFormatVersion <= SUPPORTED_TABLE_FORMAT_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ private LoadTableResponse stageCreate() {
private static List<MetadataUpdate> createChanges(TableMetadata meta) {
ImmutableList.Builder<MetadataUpdate> changes = ImmutableList.builder();

changes.add(new MetadataUpdate.AssignUUID(meta.uuid()));
changes.add(new MetadataUpdate.UpgradeFormatVersion(meta.formatVersion()));

Schema schema = meta.schema();
Expand Down

0 comments on commit 6697129

Please sign in to comment.