diff --git a/core/src/main/java/org/apache/iceberg/MetadataUpdate.java b/core/src/main/java/org/apache/iceberg/MetadataUpdate.java index ba038c196e43..65282302b5f9 100644 --- a/core/src/main/java/org/apache/iceberg/MetadataUpdate.java +++ b/core/src/main/java/org/apache/iceberg/MetadataUpdate.java @@ -338,7 +338,11 @@ public String name() { @Override public void applyTo(TableMetadata.Builder metadataBuilder) { - metadataBuilder.removeRef(refName); + if (refName.equals(SnapshotRef.MAIN_BRANCH)) { + metadataBuilder.resetMainBranch(); + } else { + metadataBuilder.removeRef(refName); + } } } diff --git a/core/src/main/java/org/apache/iceberg/TableMetadata.java b/core/src/main/java/org/apache/iceberg/TableMetadata.java index 9f6ffbcc8714..77bbfaff64e0 100644 --- a/core/src/main/java/org/apache/iceberg/TableMetadata.java +++ b/core/src/main/java/org/apache/iceberg/TableMetadata.java @@ -1297,7 +1297,7 @@ public Builder removeRef(String name) { return this; } - private Builder resetMainBranch() { + protected Builder resetMainBranch() { this.currentSnapshotId = -1; SnapshotRef ref = refs.remove(SnapshotRef.MAIN_BRANCH); if (ref != null) {