From b7573cc5203183296d86aeae4bf4aa71de0b38ee Mon Sep 17 00:00:00 2001 From: LsomeYeah Date: Mon, 21 Oct 2024 11:08:20 +0800 Subject: [PATCH] [fix][test] fix unstable random test for manifest full compaction --- .../paimon/manifest/ManifestFileMetaTest.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/paimon-core/src/test/java/org/apache/paimon/manifest/ManifestFileMetaTest.java b/paimon-core/src/test/java/org/apache/paimon/manifest/ManifestFileMetaTest.java index 32b64aa7edbe..9384eb88824d 100644 --- a/paimon-core/src/test/java/org/apache/paimon/manifest/ManifestFileMetaTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/manifest/ManifestFileMetaTest.java @@ -18,9 +18,11 @@ package org.apache.paimon.manifest; +import org.apache.paimon.data.BinaryRow; import org.apache.paimon.fs.Path; import org.apache.paimon.fs.local.LocalFileIO; import org.apache.paimon.operation.ManifestFileMerger; +import org.apache.paimon.partition.PartitionPredicate; import org.apache.paimon.types.IntType; import org.apache.paimon.types.RowType; import org.apache.paimon.utils.FailingFileIO; @@ -40,6 +42,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Set; @@ -448,7 +452,7 @@ public void testIdentifierAfterFullCompaction() throws Exception { containSameIdentifyEntryFile(fullCompacted, entryIdentifierExpected); } - @RepeatedTest(100) + @RepeatedTest(1000) public void testRandomFullCompaction() throws Exception { List input = new ArrayList<>(); Set manifestEntrySet = new HashSet<>(); @@ -485,6 +489,32 @@ public void testRandomFullCompaction() throws Exception { .collect(Collectors.toList()); long mustMergeSize = mustMergedFiles.stream().map(ManifestFileMeta::fileSize).reduce(0L, Long::sum); + // manifest files which might be merged + List toBeMerged = new LinkedList<>(input); + if (getPartitionType().getFieldCount() > 0) { + Set deletePartitions = + deleteManifestEntrySet.stream() + .map(entry -> entry.partition) + .collect(Collectors.toSet()); + PartitionPredicate predicate = + PartitionPredicate.fromMultiple(getPartitionType(), deletePartitions); + if (predicate != null) { + Iterator iterator = toBeMerged.iterator(); + while (iterator.hasNext()) { + ManifestFileMeta file = iterator.next(); + if (file.fileSize() < suggerstSize || file.numDeletedFiles() > 0) { + continue; + } + if (!predicate.test( + file.numAddedFiles() + file.numDeletedFiles(), + file.partitionStats().minValues(), + file.partitionStats().maxValues(), + file.partitionStats().nullCounts())) { + iterator.remove(); + } + } + } + } // manifest files which were not written after full compaction List notMergedFiles = input.stream() @@ -503,7 +533,7 @@ public void testRandomFullCompaction() throws Exception { if (mustMergeSize < sizeTrigger) { assertThat(fullCompacted).isEmpty(); assertThat(newMetas).isEmpty(); - } else if (mustMergedFiles.size() <= 1) { + } else if (toBeMerged.size() <= 1) { assertThat(fullCompacted).isEmpty(); assertThat(newMetas).isEmpty(); } else {