diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/migrate/HiveMigrator.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/migrate/HiveMigrator.java index e25a61e16fcb..830a01f9781c 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/migrate/HiveMigrator.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/migrate/HiveMigrator.java @@ -165,20 +165,22 @@ public void executeMigrate() throws Exception { FileStoreTable paimonTable = (FileStoreTable) hiveCatalog.getTable(identifier); checkPaimonTable(paimonTable); - List partitions = - client.listPartitions(sourceDatabase, sourceTable, Short.MAX_VALUE); checkCompatible(sourceHiveTable, paimonTable); List tasks = new ArrayList<>(); Map rollBack = new ConcurrentHashMap<>(); - if (partitions.isEmpty()) { + if (sourceHiveTable.getPartitionKeys().isEmpty()) { tasks.add( importUnPartitionedTableTask( fileIO, sourceHiveTable, paimonTable, rollBack)); } else { - tasks.addAll( - importPartitionedTableTask( - fileIO, partitions, sourceHiveTable, paimonTable, rollBack)); + List partitions = + client.listPartitions(sourceDatabase, sourceTable, Short.MAX_VALUE); + if (!partitions.isEmpty()) { + tasks.addAll( + importPartitionedTableTask( + fileIO, partitions, sourceHiveTable, paimonTable, rollBack)); + } } List> futures = diff --git a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/MigrateTableProcedureTest.scala b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/MigrateTableProcedureTest.scala index 8befd3082c5e..dcd832ba0d43 100644 --- a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/MigrateTableProcedureTest.scala +++ b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/MigrateTableProcedureTest.scala @@ -153,6 +153,21 @@ class MigrateTableProcedureTest extends PaimonHiveTestBase { } }) + test("Paimon migrate table procedure: migrate empty partitioned table") { + withTable(s"hive_tbl$random") { + spark.sql(s""" + |CREATE TABLE hive_tbl$random (id STRING, name STRING, pt STRING) + |USING parquet + |PARTITIONED BY (pt) + |""".stripMargin) + + spark.sql( + s"CALL sys.migrate_table(source_type => 'hive', table => '$hiveDbName.hive_tbl$random', options => 'file.format=parquet')") + + checkAnswer(spark.sql(s"SELECT * FROM hive_tbl$random"), Nil) + } + } + test(s"Paimon migrate table procedure: migrate partitioned table with null partition") { withTable(s"hive_tbl$random") { // create hive table