diff --git a/api/src/main/java/org/apache/iceberg/Table.java b/api/src/main/java/org/apache/iceberg/Table.java index 02db808417a4..16afdcc51904 100644 --- a/api/src/main/java/org/apache/iceberg/Table.java +++ b/api/src/main/java/org/apache/iceberg/Table.java @@ -333,6 +333,15 @@ default UpdateStatistics updateStatistics() { */ Map refs(); + /** + * Returns the UUID of the table + * + * @return the UUID of the table + */ + default String uuid() { + throw new UnsupportedOperationException(this.getClass().getName() + " doesn't implement uuid"); + } + /** * Returns the snapshot referenced by the given name or null if no such reference exists. * diff --git a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java index 5f7c48e95867..1e471a5edbbd 100644 --- a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java +++ b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java @@ -199,6 +199,11 @@ public Map refs() { return table().refs(); } + @Override + public String uuid() { + return table().uuid(); + } + @Override public String toString() { return name(); diff --git a/core/src/main/java/org/apache/iceberg/BaseTable.java b/core/src/main/java/org/apache/iceberg/BaseTable.java index 2093753bf755..4dfb33d859d8 100644 --- a/core/src/main/java/org/apache/iceberg/BaseTable.java +++ b/core/src/main/java/org/apache/iceberg/BaseTable.java @@ -259,6 +259,11 @@ public Map refs() { return ops.current().refs(); } + @Override + public String uuid() { + return ops.current().uuid(); + } + @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 c1ebd554befa..5c36666dbbd7 100644 --- a/core/src/main/java/org/apache/iceberg/BaseTransaction.java +++ b/core/src/main/java/org/apache/iceberg/BaseTransaction.java @@ -770,6 +770,11 @@ public Map refs() { return current.refs(); } + @Override + public String uuid() { + return current.uuid(); + } + @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 cf8e1b3fbaa7..2773e67f813d 100644 --- a/core/src/main/java/org/apache/iceberg/SerializableTable.java +++ b/core/src/main/java/org/apache/iceberg/SerializableTable.java @@ -67,6 +67,7 @@ public class SerializableTable implements Table, Serializable { private transient volatile Schema lazySchema = null; private transient volatile Map lazySpecs = null; private transient volatile SortOrder lazySortOrder = null; + private final String uuid; protected SerializableTable(Table table) { this.name = table.name(); @@ -83,6 +84,7 @@ protected SerializableTable(Table table) { this.encryption = table.encryption(); this.locationProvider = table.locationProvider(); this.refs = SerializableMap.copyOf(table.refs()); + this.uuid = table.uuid(); } /** @@ -247,6 +249,11 @@ public Map refs() { return refs; } + @Override + public String uuid() { + return uuid; + } + @Override public void refresh() { throw new UnsupportedOperationException(errorMsg("refresh")); diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java index 835115ad4d9c..43e2193bc823 100644 --- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java +++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java @@ -634,6 +634,8 @@ public void testCompleteCreateTable() { Assertions.assertThat(table.properties().entrySet()) .as("Table properties should be a superset of the requested properties") .containsAll(properties.entrySet()); + Assertions.assertThat(table.uuid()) + .isEqualTo(((BaseTable) table).operations().current().uuid()); } @Test