From 09f0292512cb6bfc28aa2c0f32acbbec2142dbc3 Mon Sep 17 00:00:00 2001 From: zhoulii Date: Tue, 2 Jan 2024 21:34:41 +0800 Subject: [PATCH] [flink] Ignore PartitionNotExistException on drop if exists partition statement (#2617) --- .../src/main/java/org/apache/paimon/flink/FlinkCatalog.java | 4 +++- .../java/org/apache/paimon/flink/CatalogTableITCase.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkCatalog.java b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkCatalog.java index 8ab2d2f36999..157e9b8639dd 100644 --- a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkCatalog.java +++ b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkCatalog.java @@ -927,7 +927,9 @@ public final void dropPartition( throws PartitionNotExistException, CatalogException { if (!partitionExists(tablePath, partitionSpec)) { - throw new PartitionNotExistException(getName(), tablePath, partitionSpec); + if (!ignoreIfNotExists) { + throw new PartitionNotExistException(getName(), tablePath, partitionSpec); + } } try { diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java index f662086feb2e..171ae24dd28b 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java @@ -481,6 +481,11 @@ public void testDropPartition() { .hasMessage( "Partition CatalogPartitionSpec{{dt=2020-10-10}} of table default.PartitionTable in catalog PAIMON does not exist."); + assertThat( + sql("ALTER TABLE PartitionTable DROP IF EXISTS PARTITION (`dt` = '2020-10-10')") + .toString()) + .isEqualTo("[+I[OK]]"); + List result = sql("SHOW PARTITIONS PartitionTable"); assertThat(result.toString()) .isEqualTo(