Repository navigation
fix(flink): prune partitions before incremental file checks #20995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,10 @@ | |
| import org.apache.hudi.common.config.HoodieMetadataConfig; | ||
| import org.apache.hudi.common.model.FileSlice; | ||
| import org.apache.hudi.common.model.HoodieCommitMetadata; | ||
| import org.apache.hudi.common.model.HoodiePartitionMetadata; | ||
| import org.apache.hudi.common.model.HoodieReplaceCommitMetadata; | ||
| import org.apache.hudi.common.model.HoodieTableType; | ||
| import org.apache.hudi.common.model.HoodieWriteStat; | ||
| import org.apache.hudi.common.model.WriteOperationType; | ||
| import org.apache.hudi.common.table.cdc.HoodieCDCFileSplit; | ||
| import org.apache.hudi.common.table.cdc.HoodieCDCInferenceCase; | ||
|
|
@@ -32,6 +34,7 @@ | |
| import org.apache.hudi.common.table.timeline.HoodieInstant; | ||
| import org.apache.hudi.common.table.timeline.HoodieTimeline; | ||
| import org.apache.hudi.common.table.view.HoodieTableFileSystemView; | ||
| import org.apache.hudi.common.testutils.FileCreateUtils; | ||
| import org.apache.hudi.common.testutils.HoodieCommonTestHarness; | ||
| import org.apache.hudi.common.testutils.HoodieTestUtils; | ||
| import org.apache.hudi.common.util.CommitUtils; | ||
|
|
@@ -41,6 +44,7 @@ | |
| import org.apache.hudi.sink.partitioner.profile.WriteProfiles; | ||
| import org.apache.hudi.source.prune.ColumnStatsProbe; | ||
| import org.apache.hudi.source.prune.PartitionPruners; | ||
| import org.apache.hudi.storage.StoragePath; | ||
| import org.apache.hudi.storage.StoragePathInfo; | ||
| import org.apache.hudi.table.format.cdc.CdcInputSplit; | ||
| import org.apache.hudi.table.format.mor.MergeOnReadInputSplit; | ||
|
|
@@ -64,6 +68,7 @@ | |
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.mockito.MockedStatic; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.Method; | ||
|
|
@@ -87,6 +92,9 @@ | |
| import static org.junit.jupiter.api.Assertions.assertIterableEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.CALLS_REAL_METHODS; | ||
| import static org.mockito.Mockito.mockStatic; | ||
|
|
||
| /** | ||
| * Test cases for {@link IncrementalInputSplits}. | ||
|
|
@@ -364,6 +372,134 @@ void testInputSplitsWithPartitionPruner( | |
| assertEquals(expectedPartitions, partitions); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(HoodieTableType.class) | ||
| void testIncrementalLookupChecksOnlySelectedPartitions(HoodieTableType tableType) throws Exception { | ||
| Configuration conf = TestConfigurations.getDefaultConf(basePath); | ||
| conf.set(FlinkOptions.TABLE_TYPE, tableType.name()); | ||
| metaClient = HoodieTestUtils.init(basePath, tableType); | ||
| // The split planner only needs completed commit metadata and existing file statuses. | ||
| String olderInstant = "001"; | ||
| StoragePath olderFile = new StoragePath( | ||
| FileCreateUtils.createBaseFile(metaClient, "par1", olderInstant, "file-par1", 100L)); | ||
| HoodieCommitMetadata olderMetadata = new HoodieCommitMetadata(); | ||
| olderMetadata.setOperationType(WriteOperationType.INSERT); | ||
| addFileToCommit(olderMetadata, "par1", "file-par1", olderFile); | ||
| writeFixtureCommit(tableType, olderInstant, olderMetadata); | ||
|
|
||
| String instant = "002"; | ||
| HoodieCommitMetadata metadata = new HoodieCommitMetadata(); | ||
| metadata.setOperationType(WriteOperationType.INSERT); | ||
| for (String partition : Arrays.asList("par1", "par2")) { | ||
| String fileId = "file-" + partition; | ||
| StoragePath file = new StoragePath(FileCreateUtils.createBaseFile(metaClient, partition, instant, fileId, 100L)); | ||
|
Comment on lines
+397
to
+399
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the MOR case append two distinct logs to the same selected file group in successive delta commits and assert that both paths appear in the split? With one base file per file ID, the test still passed when I routed MOR through the COW |
||
| new HoodiePartitionMetadata(metaClient.getStorage(), instant, metaClient.getBasePath(), | ||
| file.getParent(), Option.empty()).trySave(partition); | ||
| addFileToCommit(metadata, partition, fileId, file); | ||
| } | ||
| writeFixtureCommit(tableType, instant, metadata); | ||
| HoodieInstant commit = metaClient.reloadActiveTimeline().getCommitsTimeline() | ||
| .filterCompletedInstants().lastInstant().get(); | ||
| conf.set(FlinkOptions.READ_START_COMMIT, commit.getCompletionTime()); | ||
|
|
||
| IncrementalInputSplits all = IncrementalInputSplits.builder() | ||
| .conf(conf).path(new Path(basePath)).rowType(TestConfigurations.ROW_TYPE).build(); | ||
| IncrementalInputSplits selected = IncrementalInputSplits.builder() | ||
| .conf(conf).path(new Path(basePath)).rowType(TestConfigurations.ROW_TYPE) | ||
| .partitionPruner(partitions -> partitions.contains("par1") ? Collections.singleton("par1") : Collections.emptySet()) | ||
| .build(); | ||
|
|
||
| List<StoragePath> probes = new ArrayList<>(); | ||
| try (MockedStatic<StreamerUtil> streamerUtil = mockStatic(StreamerUtil.class, CALLS_REAL_METHODS)) { | ||
| streamerUtil.when(() -> StreamerUtil.fileExists(any(), any())).thenAnswer(invocation -> { | ||
| StoragePath file = invocation.getArgument(1); | ||
| probes.add(file); | ||
| return invocation.callRealMethod(); | ||
| }); | ||
|
|
||
| assertEquals(Arrays.asList("par1", "par2"), getFilteredPartitions(all.inputSplits(metaClient, false))); | ||
| assertEquals(Arrays.asList("par1", "par2"), getFilteredPartitions(all.inputSplits(metaClient, null, false))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could these two assertions compare the partition names in any order, while still checking that each occurs exactly once? Both splits have the same latest commit, so their relative order comes from iterating the partition set. Sorting the actual names before comparing would keep the duplicate-split check and allow either valid order. |
||
| List<StoragePath> excludedFiles = probes.stream().distinct() | ||
| .filter(file -> file.getParent().getName().equals("par2")).collect(Collectors.toList()); | ||
| assertFalse(excludedFiles.isEmpty()); | ||
| for (StoragePath file : excludedFiles) { | ||
| assertTrue(metaClient.getStorage().deleteFile(file)); | ||
| } | ||
|
|
||
| probes.clear(); | ||
| assertEquals(Collections.singletonList("par1"), getFilteredPartitions(selected.inputSplits(metaClient, false))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a second file group to |
||
| assertEquals(Collections.singletonList("par1"), getFilteredPartitions(selected.inputSplits(metaClient, null, false))); | ||
| assertFalse(probes.isEmpty()); | ||
| assertTrue(probes.stream().allMatch(file -> file.getParent().getName().equals("par1")), probes::toString); | ||
|
|
||
| List<StoragePath> selectedFiles = probes.stream().distinct().collect(Collectors.toList()); | ||
| for (StoragePath file : selectedFiles) { | ||
| assertTrue(metaClient.getStorage().deleteFile(file)); | ||
| } | ||
| probes.clear(); | ||
| List<MergeOnReadInputSplit> bounded = selected.inputSplits(metaClient, false).getInputSplits(); | ||
| assertEquals(1, bounded.size()); | ||
| assertEquals(olderFile.getName(), new StoragePath(bounded.get(0).getBasePath().get()).getName()); | ||
| assertTrue(selected.inputSplits(metaClient, null, false).isEmpty()); | ||
| assertFalse(probes.isEmpty()); | ||
| assertTrue(probes.stream().allMatch(file -> file.getParent().getName().equals("par1")), probes::toString); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testIncrementalLookupPreservesMultipleMorLogsForOneFileGroup() throws Exception { | ||
| String partition = "par1"; | ||
| String fileId = "file-par1"; | ||
| HoodieTableType tableType = HoodieTableType.MERGE_ON_READ; | ||
| Configuration conf = TestConfigurations.getDefaultConf(basePath); | ||
| conf.set(FlinkOptions.TABLE_TYPE, tableType.name()); | ||
| metaClient = HoodieTestUtils.init(basePath, tableType); | ||
| List<String> expectedNames = new ArrayList<>(); | ||
| for (String instant : Arrays.asList("001", "002")) { | ||
| StoragePath log = new StoragePath(FileCreateUtils.createLogFile(metaClient, partition, instant, fileId, 1, 100)); | ||
| new HoodiePartitionMetadata(metaClient.getStorage(), instant, metaClient.getBasePath(), | ||
| log.getParent(), Option.empty()).trySave(partition); | ||
| expectedNames.add(log.getName()); | ||
| HoodieCommitMetadata metadata = new HoodieCommitMetadata(); | ||
| metadata.setOperationType(WriteOperationType.UPSERT); | ||
| addFileToCommit(metadata, partition, fileId, log); | ||
| writeFixtureCommit(tableType, instant, metadata); | ||
| metaClient.reloadActiveTimeline(); | ||
| } | ||
| String firstCompletionTime = metaClient.getActiveTimeline().getCommitsTimeline() | ||
| .filterCompletedInstants().firstInstant().get().getCompletionTime(); | ||
| conf.set(FlinkOptions.READ_START_COMMIT, firstCompletionTime); | ||
| IncrementalInputSplits selected = IncrementalInputSplits.builder() | ||
| .conf(conf).path(new Path(basePath)).rowType(TestConfigurations.ROW_TYPE) | ||
| .partitionPruner(partitions -> Collections.singleton(partition)) | ||
| .build(); | ||
| for (IncrementalInputSplits.Result result : | ||
| Arrays.asList(selected.inputSplits(metaClient, false), selected.inputSplits(metaClient, null, false))) { | ||
| List<MergeOnReadInputSplit> splits = result.getInputSplits(); | ||
| assertEquals(1, splits.size()); | ||
| assertEquals(expectedNames.stream().sorted().collect(Collectors.toList()), | ||
| splits.get(0).getLogPaths().get().stream().map(path -> new StoragePath(path).getName()) | ||
| .sorted().collect(Collectors.toList())); | ||
| } | ||
| } | ||
|
|
||
| private static void addFileToCommit(HoodieCommitMetadata metadata, String partition, String fileId, StoragePath file) { | ||
| HoodieWriteStat stat = new HoodieWriteStat(); | ||
| stat.setFileId(fileId); | ||
| stat.setPartitionPath(partition); | ||
| stat.setPath(partition + "/" + file.getName()); | ||
| stat.setFileSizeInBytes(100L); | ||
| metadata.addWriteStat(partition, stat); | ||
| } | ||
|
|
||
| private void writeFixtureCommit(HoodieTableType tableType, String instant, HoodieCommitMetadata metadata) throws Exception { | ||
| if (tableType == HoodieTableType.COPY_ON_WRITE) { | ||
| FileCreateUtils.createCommit(metaClient, metaClient.getCommitMetadataSerDe(), instant, Option.of(metadata)); | ||
| } else { | ||
| FileCreateUtils.createDeltaCommit(metaClient, metaClient.getCommitMetadataSerDe(), instant, Option.empty(), metadata); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(value = HoodieTableType.class) | ||
| void testInputSplitsWithPartitionStatsPruner(HoodieTableType tableType) throws Exception { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this overload take a
Predicate<String> partitionFilterdirectly? Both planner callers can passreadPartitions::contains, and the existing unfiltered overload can passpartition -> true. That removes the nullable-set convention and this conversion while preserving the existing overloads.