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 0cd834f8ee82..31c3a28a823d 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 @@ -517,6 +517,21 @@ private Table createHiveTable(Identifier identifier, TableSchema tableSchema) { Map tblProperties; if (syncAllProperties()) { tblProperties = new HashMap<>(tableSchema.options()); + + // add primary-key, partition-key, bucket-id to tblproperties + if (!tableSchema.primaryKeys().isEmpty()) { + tblProperties.put( + CoreOptions.PRIMARY_KEY.key(), String.join(",", tableSchema.primaryKeys())); + } + if (!tableSchema.partitionKeys().isEmpty()) { + tblProperties.put( + CoreOptions.PARTITION.key(), String.join(",", tableSchema.partitionKeys())); + } + if (!tableSchema.bucketKeys().isEmpty()) { + tblProperties.put( + CoreOptions.BUCKET_KEY.key(), String.join(",", tableSchema.bucketKeys())); + } + tblProperties.put(CoreOptions.BUCKET.key(), String.valueOf(tableSchema.numBuckets())); } else { tblProperties = convertToPropertiesPrefixKey(tableSchema.options(), HIVE_PREFIX); } 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 0e8caab0d3a7..d9c38a670988 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 @@ -378,15 +378,41 @@ public void testCreateCatalogWithSyncTblProperties() throws Exception { .await(); tEnv.executeSql("USE CATALOG paimon_catalog_sync").await(); tEnv.executeSql("USE test_db").await(); - tEnv.executeSql("CREATE TABLE t01 ( aa INT, bb STRING ) WITH ( 'file.format' = 'avro' )") + tEnv.executeSql( + "CREATE TABLE t01 ( aa INT, bb STRING, cc STRING, PRIMARY KEY (cc, aa) NOT ENFORCED) PARTITIONED BY (cc) WITH ('file.format' = 'avro', 'bucket' = '3')") .await(); // assert contain properties + List descFormattedT01 = hiveShell.executeQuery("DESC FORMATTED t01"); assertThat( hiveShell .executeQuery("DESC FORMATTED t01") .contains("\tfile.format \tavro ")) .isTrue(); + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t01") + .contains("\tprimary-key \tcc,aa ")) + .isTrue(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t01") + .contains("\tpartition \tcc ")) + .isTrue(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t01") + .contains("\tbucket-key \taa ")) + .isTrue(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t01") + .contains("\tbucket \t3 ")) + .isTrue(); + tEnv.executeSql("ALTER TABLE t01 SET ( 'file.format' = 'parquet' )").await(); assertThat( hiveShell @@ -416,16 +442,42 @@ public void testCreateCatalogWithSyncTblProperties() throws Exception { .await(); tEnv.executeSql("USE CATALOG paimon_catalog_sync01").await(); tEnv.executeSql("USE test_db").await(); - tEnv.executeSql("CREATE TABLE t02 ( aa INT, bb STRING ) WITH ( 'file.format' = 'avro' )") + tEnv.executeSql( + "CREATE TABLE t02 ( aa INT, bb STRING, cc STRING, PRIMARY KEY (cc, aa) NOT ENFORCED) PARTITIONED BY (cc) WITH ('file.format' = 'avro', 'bucket' = '3')") .await(); // assert not contain properties + List descFormattedT02 = hiveShell.executeQuery("DESC FORMATTED t02"); assertThat( hiveShell .executeQuery("DESC FORMATTED t02") .contains("\tfile.format \tavro ")) .isFalse(); + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t02") + .contains("\tprimary-key \tcc,aa ")) + .isFalse(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t02") + .contains("\tpartition \tcc ")) + .isFalse(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t02") + .contains("\tbucket-key \taa ")) + .isFalse(); + + assertThat( + hiveShell + .executeQuery("DESC FORMATTED t02") + .contains("\tbucket \t3 ")) + .isFalse(); + tEnv.executeSql("ALTER TABLE t02 SET ( 'file.format' = 'parquet' )").await(); assertThat( hiveShell