You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/01/13 19:50:32 UTC

[GitHub] [iceberg] jackye1995 commented on a change in pull request #3883: Core: add snapshot reference to table metadata

jackye1995 commented on a change in pull request #3883:
URL: https://github.com/apache/iceberg/pull/3883#discussion_r784229910



##########
File path: api/src/main/java/org/apache/iceberg/Table.java
##########
@@ -138,6 +138,20 @@ default String name() {
    */
   List<HistoryEntry> history();
 
+  /**
+   * Get the snapshot references of this table.
+   *
+   * @return a map with ref name as key, {@link SnapshotRef} as value
+   */
+  Map<String, SnapshotRef> refs();
+
+  /**
+   * Get the snapshot reference with the given name
+   *
+   * @param refName snapshot reference name
+   * @return the SnapShot ref with the given name if it exists, null otherwise.
+   */
+  SnapshotRef ref(String refName);

Review comment:
       nit: newline between method definitions

##########
File path: api/src/main/java/org/apache/iceberg/SnapshotRef.java
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public class SnapshotRef implements Serializable {
+
+  public static final String MAIN_BRANCH = "main";
+
+  private final long snapshotId;
+  private final SnapshotRefType type;
+  private final Integer minSnapshotsToKeep;
+  private final Long maxSnapshotAgeMs;
+  private final Long maxRefAgeMs;
+
+  private SnapshotRef(
+      long snapshotId,
+      SnapshotRefType type,
+      Integer minSnapshotsToKeep,
+      Long maxSnapshotAgeMs,
+      Long maxRefAgeMs) {
+    this.snapshotId = snapshotId;
+    this.type = type;
+    this.minSnapshotsToKeep = minSnapshotsToKeep;
+    this.maxSnapshotAgeMs = maxSnapshotAgeMs;
+    this.maxRefAgeMs = maxRefAgeMs;
+  }
+
+  public long snapshotId() {
+    return snapshotId;
+  }
+
+  public SnapshotRefType type() {
+    return type;
+  }
+
+  public Integer minSnapshotsToKeep() {
+    return minSnapshotsToKeep;
+  }
+
+  public Long maxSnapshotAgeMs() {
+    return maxSnapshotAgeMs;
+  }
+
+  public Long maxRefAgeMs() {
+    return maxRefAgeMs;
+  }
+
+  public static Builder builderForTag(long snapshotId) {

Review comment:
       as commented by Ryan in the original PR, prefer names `tagBuilder` and `branchBuilder`

##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -501,9 +521,8 @@ public TableMetadata replaceCurrentSnapshot(Snapshot snapshot) {
     return new Builder(this).setCurrentSnapshot(snapshot).build();
   }
 
-  public TableMetadata removeSnapshotsIf(Predicate<Snapshot> removeIf) {
-    List<Snapshot> toRemove = snapshots.stream().filter(removeIf).collect(Collectors.toList());
-    return new Builder(this).removeSnapshots(toRemove).build();
+  public TableMetadata removeSnapshots(Set<Long> snapshotsToRemove) {

Review comment:
       I also created https://github.com/apache/iceberg/issues/3900 to track the new API. Not sure what is the preference, but I think it's better to have a PR that is dedicated to the new APIs and old method deprecation, because this PR is already quite long.

##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -940,9 +1029,7 @@ public Builder setCurrentSnapshot(long snapshotId) {
       return this;
     }
 
-    public Builder removeSnapshots(List<Snapshot> snapshotsToRemove) {
-      Set<Long> idsToRemove = snapshotsToRemove.stream().map(Snapshot::snapshotId).collect(Collectors.toSet());
-
+    public Builder removeSnapshots(Set<Long> idsToRemove) {

Review comment:
       nit: `snapshotIdsToRemove`

##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -501,9 +521,8 @@ public TableMetadata replaceCurrentSnapshot(Snapshot snapshot) {
     return new Builder(this).setCurrentSnapshot(snapshot).build();
   }
 
-  public TableMetadata removeSnapshotsIf(Predicate<Snapshot> removeIf) {

Review comment:
       I think we still need to keep this method for backwards API compatibility, could you mark it as deprecated instead?
   
   In the original PR I chose to skip removing snapshots with ref/branch, we can discuss what's the preferred behavior if we now decide to deprecate this method.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org