From 9748742ec9df72e76a6617df4b077c541fa6196e Mon Sep 17 00:00:00 2001 From: Yubo Xu Date: Thu, 25 Sep 2025 16:08:13 -0700 Subject: [PATCH 1/5] Fixed the unpartitioned check in replace partitions --- .../src/main/java/org/apache/iceberg/BaseReplacePartitions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java b/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java index 04611f50f15a..892257b51b0c 100644 --- a/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java +++ b/core/src/main/java/org/apache/iceberg/BaseReplacePartitions.java @@ -111,7 +111,7 @@ public void validate(TableMetadata currentMetadata, Snapshot parent) { @Override public List apply(TableMetadata base, Snapshot snapshot) { - if (dataSpec().fields().isEmpty()) { + if (dataSpec().isUnpartitioned()) { // replace all data in an unpartitioned table deleteByRowFilter(Expressions.alwaysTrue()); } From 0a71ee6e858278ebbcf2bd6f7545519129a1ee07 Mon Sep 17 00:00:00 2001 From: Yubo Xu Date: Fri, 26 Sep 2025 12:08:58 -0700 Subject: [PATCH 2/5] added new unit test --- .../apache/iceberg/TestReplacePartitions.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java index 29daeb995cc5..ab2cc87decbb 100644 --- a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java +++ b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java @@ -102,6 +102,23 @@ public class TestReplacePartitions extends TestBase { .withRecordCount(1) .build(); + static final PartitionSpec SPEC_ALL_VOID = + PartitionSpec.builderFor(SCHEMA).alwaysNull("id").alwaysNull("data").build(); + + static final DataFile FILE_ALL_VOID_UNPARTITIONED_A = + DataFiles.builder(SPEC_ALL_VOID) + .withPath("/path/to/data-all-void-unpartitioned-a.parquet") + .withFileSizeInBytes(10) + .withRecordCount(1) + .build(); + + static final DataFile FILE_ALL_VOID_UNPARTITIONED_B = + DataFiles.builder(SPEC_ALL_VOID) + .withPath("/path/to/data-all-void-unpartitioned-b.parquet") + .withFileSizeInBytes(10) + .withRecordCount(1) + .build(); + @Parameter(index = 1) private String branch; @@ -198,6 +215,40 @@ public void testReplaceWithUnpartitionedTable() throws IOException { statuses(Status.DELETED)); } + @TestTemplate + public void testReplaceAllVoidUnpartitionedTable() throws IOException { + Table tableVoid = + TestTables.create( + tableDir, "allvoidUnpartitioned", SCHEMA, SPEC_ALL_VOID, formatVersion); + + commit(tableVoid, tableVoid.newAppend().appendFile(FILE_ALL_VOID_UNPARTITIONED_A), branch); + validateSnapshot( + null, + latestSnapshot(TestTables.readMetadata("allvoidUnpartitioned"), branch), + FILE_ALL_VOID_UNPARTITIONED_A); + + ReplacePartitions replacePartitions = tableVoid.newReplacePartitions().addFile(FILE_ALL_VOID_UNPARTITIONED_B); + commit(tableVoid, replacePartitions, branch); + + assertThat(TestTables.metadataVersion("allvoidUnpartitioned")).isEqualTo(2); + TableMetadata replaceMetadata = TestTables.readMetadata("allvoidUnpartitioned"); + long replaceId = latestSnapshot(replaceMetadata, branch).snapshotId(); + + assertThat(latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io())).hasSize(2); + + validateManifestEntries( + latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(0), + ids(replaceId), + files(FILE_ALL_VOID_UNPARTITIONED_B), + statuses(Status.ADDED)); + + validateManifestEntries( + latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(1), + ids(replaceId), + files(FILE_ALL_VOID_UNPARTITIONED_A), + statuses(Status.DELETED)); + } + @TestTemplate public void testReplaceAndMergeWithUnpartitionedTable() throws IOException { Table unpartitioned = From 558fda9ee1e157615d01f5993bd9023adb00fbf1 Mon Sep 17 00:00:00 2001 From: Yubo Xu Date: Fri, 26 Sep 2025 13:59:44 -0700 Subject: [PATCH 3/5] fixed the spotless check --- .../apache/iceberg/TestReplacePartitions.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java index ab2cc87decbb..05958e88fd7e 100644 --- a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java +++ b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java @@ -103,21 +103,21 @@ public class TestReplacePartitions extends TestBase { .build(); static final PartitionSpec SPEC_ALL_VOID = - PartitionSpec.builderFor(SCHEMA).alwaysNull("id").alwaysNull("data").build(); + PartitionSpec.builderFor(SCHEMA).alwaysNull("id").alwaysNull("data").build(); static final DataFile FILE_ALL_VOID_UNPARTITIONED_A = - DataFiles.builder(SPEC_ALL_VOID) - .withPath("/path/to/data-all-void-unpartitioned-a.parquet") - .withFileSizeInBytes(10) - .withRecordCount(1) - .build(); + DataFiles.builder(SPEC_ALL_VOID) + .withPath("/path/to/data-all-void-unpartitioned-a.parquet") + .withFileSizeInBytes(10) + .withRecordCount(1) + .build(); static final DataFile FILE_ALL_VOID_UNPARTITIONED_B = - DataFiles.builder(SPEC_ALL_VOID) - .withPath("/path/to/data-all-void-unpartitioned-b.parquet") - .withFileSizeInBytes(10) - .withRecordCount(1) - .build(); + DataFiles.builder(SPEC_ALL_VOID) + .withPath("/path/to/data-all-void-unpartitioned-b.parquet") + .withFileSizeInBytes(10) + .withRecordCount(1) + .build(); @Parameter(index = 1) private String branch; @@ -218,16 +218,16 @@ public void testReplaceWithUnpartitionedTable() throws IOException { @TestTemplate public void testReplaceAllVoidUnpartitionedTable() throws IOException { Table tableVoid = - TestTables.create( - tableDir, "allvoidUnpartitioned", SCHEMA, SPEC_ALL_VOID, formatVersion); + TestTables.create(tableDir, "allvoidUnpartitioned", SCHEMA, SPEC_ALL_VOID, formatVersion); commit(tableVoid, tableVoid.newAppend().appendFile(FILE_ALL_VOID_UNPARTITIONED_A), branch); validateSnapshot( - null, - latestSnapshot(TestTables.readMetadata("allvoidUnpartitioned"), branch), - FILE_ALL_VOID_UNPARTITIONED_A); + null, + latestSnapshot(TestTables.readMetadata("allvoidUnpartitioned"), branch), + FILE_ALL_VOID_UNPARTITIONED_A); - ReplacePartitions replacePartitions = tableVoid.newReplacePartitions().addFile(FILE_ALL_VOID_UNPARTITIONED_B); + ReplacePartitions replacePartitions = + tableVoid.newReplacePartitions().addFile(FILE_ALL_VOID_UNPARTITIONED_B); commit(tableVoid, replacePartitions, branch); assertThat(TestTables.metadataVersion("allvoidUnpartitioned")).isEqualTo(2); @@ -237,16 +237,16 @@ public void testReplaceAllVoidUnpartitionedTable() throws IOException { assertThat(latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io())).hasSize(2); validateManifestEntries( - latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(0), - ids(replaceId), - files(FILE_ALL_VOID_UNPARTITIONED_B), - statuses(Status.ADDED)); + latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(0), + ids(replaceId), + files(FILE_ALL_VOID_UNPARTITIONED_B), + statuses(Status.ADDED)); validateManifestEntries( - latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(1), - ids(replaceId), - files(FILE_ALL_VOID_UNPARTITIONED_A), - statuses(Status.DELETED)); + latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(1), + ids(replaceId), + files(FILE_ALL_VOID_UNPARTITIONED_A), + statuses(Status.DELETED)); } @TestTemplate From bd03705b742ed25130cd46c476809669e45ed851 Mon Sep 17 00:00:00 2001 From: Yubo Xu Date: Fri, 26 Sep 2025 18:38:03 -0700 Subject: [PATCH 4/5] addressed pr comments --- .../java/org/apache/iceberg/TestReplacePartitions.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java index 05958e88fd7e..4afd7a3fc483 100644 --- a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java +++ b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java @@ -216,7 +216,7 @@ public void testReplaceWithUnpartitionedTable() throws IOException { } @TestTemplate - public void testReplaceAllVoidUnpartitionedTable() throws IOException { + public void testReplaceAllVoidUnpartitionedTable() { Table tableVoid = TestTables.create(tableDir, "allvoidUnpartitioned", SCHEMA, SPEC_ALL_VOID, formatVersion); @@ -233,17 +233,18 @@ public void testReplaceAllVoidUnpartitionedTable() throws IOException { assertThat(TestTables.metadataVersion("allvoidUnpartitioned")).isEqualTo(2); TableMetadata replaceMetadata = TestTables.readMetadata("allvoidUnpartitioned"); long replaceId = latestSnapshot(replaceMetadata, branch).snapshotId(); + List manifestFiles = latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()); - assertThat(latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io())).hasSize(2); + assertThat(manifestFiles).hasSize(2); validateManifestEntries( - latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(0), + manifestFiles.get(0), ids(replaceId), files(FILE_ALL_VOID_UNPARTITIONED_B), statuses(Status.ADDED)); validateManifestEntries( - latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()).get(1), + manifestFiles.get(1), ids(replaceId), files(FILE_ALL_VOID_UNPARTITIONED_A), statuses(Status.DELETED)); From eb977e000a5c966820ced850b8b330c05399965f Mon Sep 17 00:00:00 2001 From: Yubo Xu Date: Fri, 26 Sep 2025 19:11:07 -0700 Subject: [PATCH 5/5] applied spotless check fix --- .../test/java/org/apache/iceberg/TestReplacePartitions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java index 4afd7a3fc483..abc27cddd610 100644 --- a/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java +++ b/core/src/test/java/org/apache/iceberg/TestReplacePartitions.java @@ -233,7 +233,8 @@ public void testReplaceAllVoidUnpartitionedTable() { assertThat(TestTables.metadataVersion("allvoidUnpartitioned")).isEqualTo(2); TableMetadata replaceMetadata = TestTables.readMetadata("allvoidUnpartitioned"); long replaceId = latestSnapshot(replaceMetadata, branch).snapshotId(); - List manifestFiles = latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()); + List manifestFiles = + latestSnapshot(replaceMetadata, branch).allManifests(tableVoid.io()); assertThat(manifestFiles).hasSize(2);