diff --git a/core/src/main/java/org/apache/iceberg/SnapshotSummary.java b/core/src/main/java/org/apache/iceberg/SnapshotSummary.java index 460e67430b2f..e26365b56242 100644 --- a/core/src/main/java/org/apache/iceberg/SnapshotSummary.java +++ b/core/src/main/java/org/apache/iceberg/SnapshotSummary.java @@ -22,6 +22,7 @@ import java.util.Set; import org.apache.iceberg.relocated.com.google.common.base.Joiner; import org.apache.iceberg.relocated.com.google.common.base.Joiner.MapJoiner; +import org.apache.iceberg.relocated.com.google.common.base.Strings; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.relocated.com.google.common.collect.Maps; @@ -194,7 +195,7 @@ public Map build() { setIf(changedPartitions.size() > 0, builder, PARTITION_SUMMARY_PROP, "true"); for (String key : changedPartitions) { setIf( - key != null, + !Strings.isNullOrEmpty(key), builder, CHANGED_PARTITION_PREFIX + key, partitionSummary(partitionMetrics.get(key))); diff --git a/core/src/test/java/org/apache/iceberg/TestFastAppend.java b/core/src/test/java/org/apache/iceberg/TestFastAppend.java index ecc673f530e2..b6b922d41d77 100644 --- a/core/src/test/java/org/apache/iceberg/TestFastAppend.java +++ b/core/src/test/java/org/apache/iceberg/TestFastAppend.java @@ -27,6 +27,7 @@ import org.apache.iceberg.exceptions.CommitFailedException; import org.apache.iceberg.relocated.com.google.common.collect.Lists; import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.assertj.core.api.Assertions; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -405,6 +406,36 @@ public void testInvalidAppendManifest() throws IOException { () -> table.newFastAppend().appendManifest(manifestWithDeletedFiles).commit()); } + @Test + public void testPartitionSummariesOnUnpartitionedTable() { + Table table = + TestTables.create( + tableDir, + "x", + SCHEMA, + PartitionSpec.unpartitioned(), + SortOrder.unsorted(), + formatVersion); + + table.updateProperties().set(TableProperties.WRITE_PARTITION_SUMMARY_LIMIT, "1").commit(); + table + .newFastAppend() + .appendFile( + DataFiles.builder(PartitionSpec.unpartitioned()) + .withPath("/path/to/data-a.parquet") + .withFileSizeInBytes(10) + .withRecordCount(1) + .build()) + .commit(); + + Assertions.assertThat( + table.currentSnapshot().summary().keySet().stream() + .filter(key -> key.startsWith(SnapshotSummary.CHANGED_PARTITION_PREFIX)) + .collect(Collectors.toSet())) + .as("Should not include any partition summaries") + .isEmpty(); + } + @Test public void testDefaultPartitionSummaries() { table.newFastAppend().appendFile(FILE_A).commit(); diff --git a/core/src/test/java/org/apache/iceberg/TestRowDelta.java b/core/src/test/java/org/apache/iceberg/TestRowDelta.java index cce58f3e620a..4e09316bd15d 100644 --- a/core/src/test/java/org/apache/iceberg/TestRowDelta.java +++ b/core/src/test/java/org/apache/iceberg/TestRowDelta.java @@ -904,9 +904,6 @@ public void testAddDeleteFilesMultipleSpecs() { Assert.assertEquals("Should add 3 position deletes", "3", summary.get(ADDED_POS_DELETES_PROP)); Assert.assertEquals("Should have 3 position deletes", "3", summary.get(TOTAL_POS_DELETES_PROP)); - Assert.assertTrue( - "Partition metrics must be correct", - summary.get(CHANGED_PARTITION_PREFIX).contains(ADDED_DELETE_FILES_PROP + "=1")); Assert.assertTrue( "Partition metrics must be correct", summary