This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 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 fb1052770f [hive] Preserve default partition name when copying Hive 
tables (#6829)
fb1052770f is described below

commit fb1052770f994640f9d17c46c1b7953aa16fe454
Author: Zouxxyy <[email protected]>
AuthorDate: Fri Dec 19 10:13:14 2025 +0800

    [hive] Preserve default partition name when copying Hive tables (#6829)
---
 .../java/org/apache/paimon/hive/clone/HiveCloneUtils.java   |  8 ++++++++
 .../java/org/apache/paimon/hive/migrate/HiveMigrator.java   | 13 +++++++++++--
 .../paimon/spark/procedure/MigrateTableProcedureTest.scala  |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/clone/HiveCloneUtils.java
 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/clone/HiveCloneUtils.java
index 2672aaa450..f1d412ace1 100644
--- 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/clone/HiveCloneUtils.java
+++ 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/clone/HiveCloneUtils.java
@@ -47,6 +47,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.Predicate;
 
+import static org.apache.paimon.CoreOptions.PARTITION_DEFAULT_NAME;
 import static org.apache.paimon.hive.HiveTypeUtils.toPaimonType;
 
 /** Utils for cloning Hive table to Paimon table. */
@@ -151,6 +152,13 @@ public class HiveCloneUtils {
         List<FieldSchema> fields = extractor.extractSchema(client, hiveTable, 
database, table);
         List<String> partitionKeys = extractor.extractPartitionKeys(hiveTable);
         Map<String, String> options = extractor.extractOptions(hiveTable);
+        if (hiveTable.isSetPartitionKeys()) {
+            options.put(
+                    PARTITION_DEFAULT_NAME.key(),
+                    client.getConfigValue(
+                            "hive.exec.default.partition.name", 
"__HIVE_DEFAULT_PARTITION__"));
+        }
+
         Schema.Builder schemaBuilder =
                 Schema.newBuilder()
                         .comment(options.get("comment"))
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 ca8c56b2eb..e25a61e16f 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
@@ -57,6 +57,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.stream.Collectors;
 
+import static org.apache.paimon.CoreOptions.PARTITION_DEFAULT_NAME;
 import static org.apache.paimon.hive.HiveTypeUtils.toPaimonType;
 import static org.apache.paimon.hive.clone.HiveCloneUtils.HIDDEN_PATH_FILTER;
 import static org.apache.paimon.hive.clone.HiveCloneUtils.parseFormat;
@@ -147,11 +148,15 @@ public class HiveMigrator implements Migrator {
         try {
             hiveCatalog.getTable(identifier);
         } catch (Catalog.TableNotExistException e) {
+            String defaultPartitionName =
+                    client.getConfigValue(
+                            "hive.exec.default.partition.name", 
"__HIVE_DEFAULT_PARTITION__");
             Schema schema =
                     from(
                             client.getSchema(sourceDatabase, sourceTable),
                             sourceHiveTable.getPartitionKeys(),
-                            properties);
+                            properties,
+                            defaultPartitionName);
             hiveCatalog.createTable(identifier, schema, false);
             deleteIfFail = true;
         }
@@ -254,7 +259,8 @@ public class HiveMigrator implements Migrator {
     public Schema from(
             List<FieldSchema> fields,
             List<FieldSchema> partitionFields,
-            Map<String, String> hiveTableOptions) {
+            Map<String, String> hiveTableOptions,
+            String defaultPartitionName) {
         checkArgument(
                 coreOptions.bucket() == -1,
                 "Hive migrator only support unaware-bucket target table, 
bucket should be -1");
@@ -263,6 +269,9 @@ public class HiveMigrator implements Migrator {
         if (hiveTableOptions.get("comment") != null) {
             paimonOptions.put("hive.comment", hiveTableOptions.get("comment"));
         }
+        if (!partitionFields.isEmpty()) {
+            paimonOptions.put(PARTITION_DEFAULT_NAME.key(), 
defaultPartitionName);
+        }
 
         Schema.Builder schemaBuilder =
                 Schema.newBuilder()
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 946681e07a..8befd3082c 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
@@ -170,7 +170,7 @@ class MigrateTableProcedureTest extends PaimonHiveTestBase {
 
       spark.sql(
         s"""CALL sys.migrate_table(source_type => 'hive', table => 
'$hiveDbName.hive_tbl$random',
-           |options => 
'file.format=parquet,partition.default-name=__HIVE_DEFAULT_PARTITION__')
+           |options => 'file.format=orc')
            |""".stripMargin)
 
       checkAnswer(

Reply via email to