This is an automated email from the ASF dual-hosted git repository.

jackye pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new dafb4801e6 Core, API: Add getting refs and snapshot by ref to the 
Table API (#4428)
dafb4801e6 is described below

commit dafb4801e657f0874ece1be41fc5dcc2522a1255
Author: Amogh Jahagirdar <[email protected]>
AuthorDate: Fri Aug 5 09:35:18 2022 -0700

    Core, API: Add getting refs and snapshot by ref to the Table API (#4428)
---
 .palantir/revapi.yml                                |  3 +++
 api/src/main/java/org/apache/iceberg/Table.java     | 21 +++++++++++++++++++++
 .../java/org/apache/iceberg/BaseMetadataTable.java  |  5 +++++
 .../src/main/java/org/apache/iceberg/BaseTable.java |  5 +++++
 .../java/org/apache/iceberg/BaseTransaction.java    |  5 +++++
 .../java/org/apache/iceberg/SerializableTable.java  |  7 +++++++
 6 files changed, 46 insertions(+)

diff --git a/.palantir/revapi.yml b/.palantir/revapi.yml
index 37e95468b4..9b2523db9e 100644
--- a/.palantir/revapi.yml
+++ b/.palantir/revapi.yml
@@ -45,6 +45,9 @@ acceptedBreaks:
     - code: "java.method.addedToInterface"
       new: "method java.util.List<org.apache.iceberg.ManifestFile> 
org.apache.iceberg.Snapshot::deleteManifests(org.apache.iceberg.io.FileIO)"
       justification: "Allow adding a new method to the interface - old method 
is deprecated"
+    - code: "java.method.addedToInterface"
+      new: "method java.util.Map<java.lang.String, 
org.apache.iceberg.SnapshotRef> org.apache.iceberg.Table::refs()"
+      justification: "Adding new refs method to Table API for easier access"
     - code: "java.method.addedToInterface"
       new: "method long 
org.apache.iceberg.actions.ExpireSnapshots.Result::deletedEqualityDeleteFilesCount()"
       justification: "Interface is backward compatible, very unlikely anyone 
implements this Result bean interface"
diff --git a/api/src/main/java/org/apache/iceberg/Table.java 
b/api/src/main/java/org/apache/iceberg/Table.java
index 8278c99bfc..7964bd22c0 100644
--- a/api/src/main/java/org/apache/iceberg/Table.java
+++ b/api/src/main/java/org/apache/iceberg/Table.java
@@ -305,4 +305,25 @@ public interface Table {
 
   /** Returns a {@link LocationProvider} to provide locations for new data 
files. */
   LocationProvider locationProvider();
+
+  /**
+   * Returns the current refs for the table
+   *
+   * @return the current refs for the table
+   */
+  Map<String, SnapshotRef> refs();
+
+  /**
+   * Returns the snapshot referenced by the given name or null if no such 
reference exists.
+   *
+   * @return the snapshot which is referenced by the given name or null if no 
such reference exists.
+   */
+  default Snapshot snapshot(String name) {
+    SnapshotRef ref = refs().get(name);
+    if (ref != null) {
+      return snapshot(ref.snapshotId());
+    }
+
+    return null;
+  }
 }
diff --git a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java 
b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java
index b065ade32b..c6615862de 100644
--- a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java
+++ b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java
@@ -158,6 +158,11 @@ public abstract class BaseMetadataTable implements Table, 
HasTableOperations, Se
     return table().history();
   }
 
+  @Override
+  public Map<String, SnapshotRef> refs() {
+    return table().refs();
+  }
+
   @Override
   public UpdateSchema updateSchema() {
     throw new UnsupportedOperationException("Cannot update the schema of a 
metadata table");
diff --git a/core/src/main/java/org/apache/iceberg/BaseTable.java 
b/core/src/main/java/org/apache/iceberg/BaseTable.java
index d79c46050f..48a78cce3b 100644
--- a/core/src/main/java/org/apache/iceberg/BaseTable.java
+++ b/core/src/main/java/org/apache/iceberg/BaseTable.java
@@ -244,6 +244,11 @@ public class BaseTable implements Table, 
HasTableOperations, Serializable {
     return operations().locationProvider();
   }
 
+  @Override
+  public Map<String, SnapshotRef> refs() {
+    return ops.current().refs();
+  }
+
   @Override
   public String toString() {
     return name();
diff --git a/core/src/main/java/org/apache/iceberg/BaseTransaction.java 
b/core/src/main/java/org/apache/iceberg/BaseTransaction.java
index 38dfa0aaf3..b162201cf5 100644
--- a/core/src/main/java/org/apache/iceberg/BaseTransaction.java
+++ b/core/src/main/java/org/apache/iceberg/BaseTransaction.java
@@ -747,6 +747,11 @@ public class BaseTransaction implements Transaction {
       return transactionOps.locationProvider();
     }
 
+    @Override
+    public Map<String, SnapshotRef> refs() {
+      return current.refs();
+    }
+
     @Override
     public String toString() {
       return name();
diff --git a/core/src/main/java/org/apache/iceberg/SerializableTable.java 
b/core/src/main/java/org/apache/iceberg/SerializableTable.java
index 37d7453c03..ddffdae14e 100644
--- a/core/src/main/java/org/apache/iceberg/SerializableTable.java
+++ b/core/src/main/java/org/apache/iceberg/SerializableTable.java
@@ -61,6 +61,7 @@ public class SerializableTable implements Table, Serializable 
{
   private final FileIO io;
   private final EncryptionManager encryption;
   private final LocationProvider locationProvider;
+  private final Map<String, SnapshotRef> refs;
 
   private transient volatile Table lazyTable = null;
   private transient volatile Schema lazySchema = null;
@@ -81,6 +82,7 @@ public class SerializableTable implements Table, Serializable 
{
     this.io = fileIO(table);
     this.encryption = table.encryption();
     this.locationProvider = table.locationProvider();
+    this.refs = table.refs();
   }
 
   /**
@@ -235,6 +237,11 @@ public class SerializableTable implements Table, 
Serializable {
     return locationProvider;
   }
 
+  @Override
+  public Map<String, SnapshotRef> refs() {
+    return refs;
+  }
+
   @Override
   public void refresh() {
     throw new UnsupportedOperationException(errorMsg("refresh"));

Reply via email to