From 6225a9c35aea18c5a18d7344b2e0580d7e84b7ca Mon Sep 17 00:00:00 2001 From: ajantha-bhat Date: Sat, 16 Dec 2023 15:27:53 +0530 Subject: [PATCH 1/2] Core: Fix Metadata table's UUID --- .../java/org/apache/iceberg/BaseMetadataTable.java | 4 +++- .../org/apache/iceberg/TestMetadataTableScans.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java index 124115496b3e..4565b898c43d 100644 --- a/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java +++ b/core/src/main/java/org/apache/iceberg/BaseMetadataTable.java @@ -44,6 +44,7 @@ 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"); @@ -51,6 +52,7 @@ protected BaseMetadataTable(Table table, String name) { table instanceof BaseTable, "Cannot create metadata table for non-data table: %s", table); this.table = (BaseTable) table; this.name = name; + this.uuid = UUID.randomUUID(); } /** @@ -202,7 +204,7 @@ public Map refs() { @Override public UUID uuid() { - return UUID.randomUUID(); + return uuid; } @Override diff --git a/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java b/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java index 9da1838ad2e4..2cf2e984f0dc 100644 --- a/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java +++ b/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java @@ -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; @@ -138,6 +139,18 @@ public void testManifestsTableAlwaysIgnoresResiduals() throws IOException { } } + @Test + public void testManifestsTableUUID() { + 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 main table UUID") + .isNotEqualTo(table.uuid()); + } + @Test public void testDataFilesTableWithDroppedPartition() throws IOException { table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit(); From 180a3ccf23e603407e3279afd1f7209eb64657c8 Mon Sep 17 00:00:00 2001 From: ajantha-bhat Date: Sat, 16 Dec 2023 22:59:26 +0530 Subject: [PATCH 2/2] Address nits --- .../test/java/org/apache/iceberg/TestMetadataTableScans.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java b/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java index 2cf2e984f0dc..aa1da6b182dc 100644 --- a/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java +++ b/core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java @@ -140,14 +140,14 @@ public void testManifestsTableAlwaysIgnoresResiduals() throws IOException { } @Test - public void testManifestsTableUUID() { + 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 main table UUID") + .as("Metadata table UUID should be different from the base table UUID") .isNotEqualTo(table.uuid()); }