amogh-jahagirdar commented on a change in pull request #4071:
URL: https://github.com/apache/iceberg/pull/4071#discussion_r837054995
##########
File path: core/src/main/java/org/apache/iceberg/MetadataUpdate.java
##########
@@ -223,31 +225,117 @@ 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;
-
- public SetSnapshotRef(String name, long snapshotId) {
- this.name = name;
+ private final String ref;
+ private final Long snapshotId;
+ private final SnapshotRefType type;
+ private final Integer minSnapshotsToKeep;
+ private final Long maxSnapshotAgeMs;
+ private final 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 String name() {
- return name;
+ @SuppressWarnings("checkstyle:HiddenField")
+ public static class Builder {
+ private final String ref;
+ private final SnapshotRefType type;
+ private long snapshotId;
+ private Integer minSnapshotsToKeep;
+ private Long maxSnapshotAgeMs;
+ private Long maxRefAgeMs;
+
+ public Builder(final String ref, final SnapshotRefType type, final long
snapshotId) {
+ this.ref = ref;
+ this.type = type;
+ this.snapshotId = snapshotId;
+ }
+
+ public Builder minSnapshotsToKeep(Integer minSnapshotsToKeep) {
+ this.minSnapshotsToKeep = minSnapshotsToKeep;
+ return this;
+ }
+
+ public Builder maxSnapshotAgeMs(Long maxSnapshotAgeMs) {
+ this.maxSnapshotAgeMs = maxSnapshotAgeMs;
+ return this;
+ }
+
+ public Builder maxRefAgeMs(Long maxRefAgeMs) {
+ this.maxRefAgeMs = maxRefAgeMs;
+ return this;
+ }
+
+ public SetSnapshotRef build() {
+ return new SetSnapshotRef(ref, snapshotId, type, minSnapshotsToKeep,
maxSnapshotAgeMs, maxRefAgeMs);
+ }
+ }
+
+ 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);
+ SnapshotRef.Builder builder;
+ boolean newRef = currentRef == null;
+
+ if (!newRef) {
+ builder = SnapshotRef.builderFrom(currentRef);
+ } else {
+ builder = SnapshotRef.builderFor(snapshotId, type);
+ }
+
+ if (newRef || (currentRef.isBranch() && minSnapshotsToKeep != null)) {
+ builder.minSnapshotsToKeep(minSnapshotsToKeep);
+ }
+ if (newRef || (currentRef.isBranch() && maxSnapshotAgeMs != null)) {
+ builder.maxSnapshotAgeMs(maxSnapshotAgeMs);
+ }
+ if (newRef || maxRefAgeMs != null) {
+ builder.maxRefAgeMs(maxRefAgeMs);
+ }
Review comment:
Ah oops. I need to actually build the ref and set it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]