diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java index 30375e246443..efed642c8337 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java @@ -41,6 +41,7 @@ import org.apache.paimon.schema.SchemaManager; import org.apache.paimon.schema.TableSchema; import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.FileStoreTableFactory; import org.apache.paimon.table.TableType; import org.apache.paimon.types.DataField; import org.apache.paimon.types.DataTypes; @@ -338,14 +339,15 @@ private boolean partitionExistsInOtherBranches( continue; } + Optional branchSchema = + tableSchemaInFileSystem(mainTable.location(), branchName); + if (!branchSchema.isPresent()) { + continue; + } + FileStoreTable table = - (FileStoreTable) - getTable( - new Identifier( - identifier.getDatabaseName(), - identifier.getTableName(), - branchName, - null)); + FileStoreTableFactory.create( + mainTable.fileIO(), mainTable.location(), branchSchema.get()); if (!table.newScan().withPartitionFilter(partitionSpec).listPartitions().isEmpty()) { return true; } diff --git a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java index fb504f5594e4..3dd8cb251817 100644 --- a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java +++ b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java @@ -487,6 +487,16 @@ public void testFlinkCreateBranchAndHiveRead() throws Exception { @Test public void testDropPartitionFromBranch() throws Exception { + testDropPartitionFromBranchImpl(); + } + + @Test + @LocationInProperties + public void testDropPartitionFromBranchLocationInProperties() throws Exception { + testDropPartitionFromBranchImpl(); + } + + private void testDropPartitionFromBranchImpl() throws Exception { tEnv.executeSql( "CREATE TABLE t ( pt INT, v STRING ) PARTITIONED BY (pt) " + "WITH ( 'file.format' = 'avro', 'metastore.partitioned-table' = 'true' )")