This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 5374b7d131 [flink] Apply the partition argument of the
remove_unexisting_files action (#10926)
5374b7d131 is described below
commit 5374b7d131fba0bad6907e3920cb720b703c11b4
Author: YangJie <[email protected]>
AuthorDate: Mon Nov 2 01:14:22 2026 -0500
[flink] Apply the partition argument of the remove_unexisting_files action
(#10926)
---
.../flink/action/RemoveUnexistingFilesAction.java | 46 ++++++++++-
.../action/RemoveUnexistingFilesActionFactory.java | 4 +
.../action/RemoveUnexistingFilesActionITCase.java | 94 ++++++++++++++++++++++
3 files changed, 141 insertions(+), 3 deletions(-)
diff --git
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesAction.java
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesAction.java
index 5639da0871..444a22c2fb 100644
---
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesAction.java
+++
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesAction.java
@@ -28,6 +28,7 @@ import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.io.DataIncrement;
import org.apache.paimon.memory.MemorySegment;
import org.apache.paimon.operation.ListUnexistingFiles;
+import org.apache.paimon.partition.PartitionPredicate;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.table.sink.CommitMessage;
import org.apache.paimon.table.sink.CommitMessageImpl;
@@ -39,6 +40,8 @@ import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import org.apache.flink.util.OutputTag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
@@ -81,8 +84,11 @@ public class RemoveUnexistingFilesAction extends
TableActionBase {
private static final OutputTag<String> RESULT_SIDE_OUTPUT =
new OutputTag<>("result-side-output",
BasicTypeInfo.STRING_TYPE_INFO);
+ private static final Logger LOG =
LoggerFactory.getLogger(RemoveUnexistingFilesAction.class);
+
private boolean dryRun = false;
@Nullable private Integer parallelism = null;
+ @Nullable private List<Map<String, String>> partitions = null;
public RemoveUnexistingFilesAction(
String databaseName, String tableName, Map<String, String>
catalogConfig) {
@@ -99,15 +105,42 @@ public class RemoveUnexistingFilesAction extends
TableActionBase {
return this;
}
+ public RemoveUnexistingFilesAction withPartitions(List<Map<String,
String>> partitions) {
+ this.partitions = partitions;
+ return this;
+ }
+
@Override
public void build() throws Exception {
buildDataStream();
}
public DataStream<String> buildDataStream() throws Exception {
+ return buildDataStream(selectPartitions());
+ }
+
+ private List<BinaryRow> selectPartitions() throws Exception {
FileStoreTable fileStoreTable = (FileStoreTable) table;
- List<BinaryRow> binaryPartitions =
fileStoreTable.newScan().listPartitions();
+ List<BinaryRow> allPartitions =
fileStoreTable.newScan().listPartitions();
+ if (partitions == null) {
+ return allPartitions;
+ }
+ PartitionPredicate partitionPredicate =
+ ActionPartitionPredicate.create(
+ fileStoreTable, partitions, null,
"remove_unexisting_files");
+ List<BinaryRow> selected =
+ allPartitions.stream()
+ .filter(partitionPredicate::test)
+ .collect(Collectors.toList());
+ LOG.info(
+ "{} of {} partitions match the specified partitions.",
+ selected.size(),
+ allPartitions.size());
+ return selected;
+ }
+ private DataStream<String> buildDataStream(List<BinaryRow>
binaryPartitions) {
+ FileStoreTable fileStoreTable = (FileStoreTable) table;
SingleOutputStreamOperator<byte[]> source =
StreamExecutionEnvironmentUtils.fromData(
env,
@@ -124,7 +157,9 @@ public class RemoveUnexistingFilesAction extends
TableActionBase {
new CommittableTypeInfo(),
new WorkerOperator(fileStoreTable));
if (parallelism != null) {
- worker = worker.setParallelism(Math.min(parallelism,
binaryPartitions.size()));
+ worker =
+ worker.setParallelism(
+ Math.min(parallelism, Math.max(1,
binaryPartitions.size())));
}
DataStream<String> result = worker.getSideOutput(RESULT_SIDE_OUTPUT);
@@ -142,7 +177,12 @@ public class RemoveUnexistingFilesAction extends
TableActionBase {
@Override
public void run() throws Exception {
- build();
+ List<BinaryRow> binaryPartitions = selectPartitions();
+ if (binaryPartitions.isEmpty()) {
+ LOG.info("No partition to check in table {}.", table.name());
+ return;
+ }
+ buildDataStream(binaryPartitions);
env.execute("Remove Unexisting Files : " + table.name());
}
diff --git
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionFactory.java
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionFactory.java
index 462121ed2d..f01c3e507b 100644
---
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionFactory.java
+++
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionFactory.java
@@ -44,6 +44,10 @@ public class RemoveUnexistingFilesActionFactory implements
ActionFactory {
action.dryRun();
}
+ if (params.has(PARTITION)) {
+ action.withPartitions(getPartitions(params));
+ }
+
if (params.has(PARALLELISM)) {
action.withParallelism(Integer.parseInt(params.get(PARALLELISM)));
}
diff --git
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionITCase.java
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionITCase.java
index a16cd1681c..f05248d3c5 100644
---
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionITCase.java
+++
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/RemoveUnexistingFilesActionITCase.java
@@ -18,11 +18,16 @@
package org.apache.paimon.flink.action;
+import org.apache.paimon.fs.FileStatus;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.operation.ListUnexistingFilesTest;
+import org.apache.paimon.table.FileStoreTable;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.types.Row;
import org.apache.flink.util.CloseableIterator;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -34,6 +39,95 @@ import static org.assertj.core.api.Assertions.assertThat;
/** IT cases for {@link RemoveUnexistingFilesAction}. */
public class RemoveUnexistingFilesActionITCase extends ActionITCaseBase {
+ @Test
+ public void testPartitionArgument() throws Exception {
+ int[] numDeletes = prepareTableMissingFilesInEveryPartition();
+
+ // only repair pt=0
+ createAction(
+ RemoveUnexistingFilesAction.class,
+ "remove_unexisting_files",
+ "--warehouse",
+ warehouse,
+ "--database",
+ "mydb",
+ "--table",
+ "t",
+ "--partition",
+ "pt=0")
+ .withParallelism(2)
+ .run();
+
+ // the missing files of pt=1 are still in the manifest
+ assertThat(countUnexistingFiles()).containsExactly(0, numDeletes[1]);
+ }
+
+ @Test
+ public void testPartitionArgumentMatchingNothing() throws Exception {
+ int[] numDeletes = prepareTableMissingFilesInEveryPartition();
+
+ createAction(
+ RemoveUnexistingFilesAction.class,
+ "remove_unexisting_files",
+ "--warehouse",
+ warehouse,
+ "--database",
+ "mydb",
+ "--table",
+ "t",
+ "--partition",
+ "pt=99")
+ .withParallelism(2)
+ .run();
+
+ assertThat(countUnexistingFiles()).containsExactly(numDeletes);
+ }
+
+ private int[] prepareTableMissingFilesInEveryPartition() throws Exception {
+ int[] numDeletes = new int[2];
+ FileStoreTable table =
+ ListUnexistingFilesTest.prepareRandomlyDeletedTable(
+ warehouse, "mydb", "t", -1, 10, numDeletes, false);
+ LocalFileIO fileIO = LocalFileIO.create();
+ for (int i = 0; i < numDeletes.length; i++) {
+ if (numDeletes[i] == 0) {
+ FileStatus[] files =
+ fileIO.listStatus(new Path(table.location(), "pt=" + i
+ "/bucket-0"));
+ fileIO.deleteQuietly(files[0].getPath());
+ numDeletes[i] = 1;
+ }
+ }
+ return numDeletes;
+ }
+
+ /** Counts the unexisting files per partition with a dry run over the
whole table. */
+ private int[] countUnexistingFiles() throws Exception {
+ RemoveUnexistingFilesAction action =
+ createAction(
+ RemoveUnexistingFilesAction.class,
+ "remove_unexisting_files",
+ "--warehouse",
+ warehouse,
+ "--database",
+ "mydb",
+ "--table",
+ "t",
+ "--dry_run",
+ "true")
+ .withParallelism(2);
+ int[] actual = new int[2];
+ Pattern pattern = Pattern.compile("pt=(\\d+?)/");
+ try (CloseableIterator<String> it =
action.buildDataStream().executeAndCollect()) {
+ while (it.hasNext()) {
+ Matcher matcher = pattern.matcher(it.next());
+ if (matcher.find()) {
+ actual[Integer.parseInt(matcher.group(1))]++;
+ }
+ }
+ }
+ return actual;
+ }
+
@ParameterizedTest
@ValueSource(ints = {-1, 3})
public void testAction(int bucket) throws Exception {