Skip to content

Commit

Permalink
Core: Fix metadata table uuid to return a consistent UUID for the sam…
Browse files Browse the repository at this point in the history
…e reference (apache#9310)
  • Loading branch information
ajantha-bhat authored Dec 16, 2023
1 parent 395e01e commit 24578a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/apache/iceberg/BaseMetadataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public abstract class BaseMetadataTable extends BaseReadOnlyTable
private final SortOrder sortOrder = SortOrder.unsorted();
private final BaseTable table;
private final String name;
private final UUID uuid;

protected BaseMetadataTable(Table table, String name) {
super("metadata");
Preconditions.checkArgument(
table instanceof BaseTable, "Cannot create metadata table for non-data table: %s", table);
this.table = (BaseTable) table;
this.name = name;
this.uuid = UUID.randomUUID();
}

/**
Expand Down Expand Up @@ -202,7 +204,7 @@ public Map<String, SnapshotRef> refs() {

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

@Override
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.iceberg.relocated.com.google.common.collect.Streams;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.StructLikeWrapper;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
Expand Down Expand Up @@ -138,6 +139,18 @@ public void testManifestsTableAlwaysIgnoresResiduals() throws IOException {
}
}

@Test
public void testMetadataTableUUID() {
Table manifestsTable = new ManifestsTable(table);

Assertions.assertThat(manifestsTable.uuid())
.as("UUID should be consistent on multiple calls")
.isEqualTo(manifestsTable.uuid());
Assertions.assertThat(manifestsTable.uuid())
.as("Metadata table UUID should be different from the base table UUID")
.isNotEqualTo(table.uuid());
}

@Test
public void testDataFilesTableWithDroppedPartition() throws IOException {
table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
Expand Down

0 comments on commit 24578a2

Please sign in to comment.