Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API, Core: Add UUID API to Table #8800

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
amogh-jahagirdar marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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