rdblue commented on code in PR #4071: URL: https://github.com/apache/iceberg/pull/4071#discussion_r841294191
########## core/src/main/java/org/apache/iceberg/MetadataUpdate.java: ########## @@ -223,31 +225,106 @@ public String name() { @Override public void applyTo(TableMetadata.Builder metadataBuilder) { - // TODO: this should be generalized when tagging is supported - metadataBuilder.removeBranch(name); + SnapshotRef ref = metadataBuilder.ref(name); + ValidationException.check(ref != null, "Ref %s not found", name); + if (ref.isBranch()) { + metadataBuilder.removeBranch(name); + } else { + metadataBuilder.removeTag(name); + } } } class SetSnapshotRef implements MetadataUpdate { - private final String name; - private final long snapshotId; + private final String ref; + private final Long snapshotId; + private final SnapshotRefType type; + private Integer minSnapshotsToKeep; + private Long maxSnapshotAgeMs; + private Long maxRefAgeMs; + + public SetSnapshotRef(String ref, Long snapshotId, SnapshotRefType type, Integer minSnapshotsToKeep, + Long maxSnapshotAgeMs, Long maxRefAgeMs) { + this.ref = ref; + this.snapshotId = snapshotId; + this.type = type; + this.minSnapshotsToKeep = minSnapshotsToKeep; + this.maxSnapshotAgeMs = maxSnapshotAgeMs; + this.maxRefAgeMs = maxRefAgeMs; + } - public SetSnapshotRef(String name, long snapshotId) { - this.name = name; + public SetSnapshotRef(String ref, Long snapshotId, SnapshotRefType type) { + this.ref = ref; this.snapshotId = snapshotId; + this.type = type; } - public String name() { - return name; + public String ref() { + return ref; + } + + public SnapshotRefType type() { + return type; } public long snapshotId() { return snapshotId; } + public Integer minSnapshotsToKeep() { + return minSnapshotsToKeep; + } + + public Long maxSnapshotAgeMs() { + return maxSnapshotAgeMs; + } + + public Long maxRefAgeMs() { + return maxRefAgeMs; + } + @Override public void applyTo(TableMetadata.Builder metadataBuilder) { - metadataBuilder.setBranchSnapshot(snapshotId, name); + SnapshotRef currentRef = metadataBuilder.ref(ref); + Preconditions.checkArgument(currentRef == null || currentRef.type() == type, + "Cannot apply SetSnapshotRef where current ref is of type %s and update is of type %s", + currentRef.type(), type); Review Comment: I don't think we need this check. Changes that come through should be idempotent, or should use requirements to validate that they can be applied. If there's a need for a requirement we can look into adding one. But I think it should be fine if this just goes ahead with the update. We already check in requirements that the referenced snapshot has not changed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org