Skip to content

Commit

Permalink
API, Core: Add uuid API to Table
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh-jahagirdar committed Oct 28, 2023
1 parent b5ea0d5 commit fdac953
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/src/main/java/org/apache/iceberg/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.LocationProvider;
Expand Down Expand Up @@ -333,6 +334,15 @@ default UpdateStatistics updateStatistics() {
*/
Map<String, SnapshotRef> refs();

/**
* Returns the UUID of the table
*
* @return the UUID of the table
*/
default UUID 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.
*
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/apache/iceberg/BaseMetadataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.io.FileIO;
Expand Down Expand Up @@ -199,6 +200,11 @@ public Map<String, SnapshotRef> refs() {
return table().refs();
}

@Override
public UUID uuid() {
return UUID.randomUUID();
}

@Override
public String toString() {
return name();
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/apache/iceberg/BaseTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.LocationProvider;
Expand Down Expand Up @@ -259,6 +260,11 @@ public Map<String, SnapshotRef> refs() {
return ops.current().refs();
}

@Override
public UUID uuid() {
return UUID.fromString(ops.current().uuid());
}

@Override
public String toString() {
return name();
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/apache/iceberg/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.iceberg.encryption.EncryptionManager;
Expand Down Expand Up @@ -770,6 +771,11 @@ public Map<String, SnapshotRef> refs() {
return current.refs();
}

@Override
public UUID uuid() {
return UUID.fromString(current.uuid());
}

@Override
public String toString() {
return name();
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/apache/iceberg/SerializableTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.hadoop.HadoopConfigurable;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class SerializableTable implements Table, Serializable {
private transient volatile Schema lazySchema = null;
private transient volatile Map<Integer, PartitionSpec> lazySpecs = null;
private transient volatile SortOrder lazySortOrder = null;
private final UUID uuid;

protected SerializableTable(Table table) {
this.name = table.name();
Expand All @@ -83,6 +85,7 @@ protected SerializableTable(Table table) {
this.encryption = table.encryption();
this.locationProvider = table.locationProvider();
this.refs = SerializableMap.copyOf(table.refs());
this.uuid = table.uuid();
}

/**
Expand Down Expand Up @@ -247,6 +250,11 @@ public Map<String, SnapshotRef> refs() {
return refs;
}

@Override
public UUID uuid() {
return uuid;
}

@Override
public void refresh() {
throw new UnsupportedOperationException(errorMsg("refresh"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.iceberg.AppendFiles;
import org.apache.iceberg.BaseTable;
Expand Down Expand Up @@ -634,6 +635,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(UUID.fromString(((BaseTable) table).operations().current().uuid()));
}

@Test
Expand Down

0 comments on commit fdac953

Please sign in to comment.