From 8510af3a7f49d0c6e90ad9ff8a267fa905936656 Mon Sep 17 00:00:00 2001 From: Chuang Li <64473732+CodeCooker17@users.noreply.github.com> Date: Sun, 3 Sep 2023 11:16:46 +0800 Subject: [PATCH] [fix](hive external) support set hive version when create hive external table (#20622) --- .../src/main/java/org/apache/doris/catalog/HiveTable.java | 6 ++++++ .../java/org/apache/doris/datasource/InternalCatalog.java | 3 +++ .../test/java/org/apache/doris/catalog/HiveTableTest.java | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java index 9f9dadbbe7..550be96f74 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java @@ -106,6 +106,12 @@ public class HiveTable extends Table { } copiedProps.remove(HMSProperties.HIVE_METASTORE_URIS); hiveProperties.put(HMSProperties.HIVE_METASTORE_URIS, hiveMetaStoreUris); + // support multi hive version + String hiveVersion = copiedProps.get(HMSProperties.HIVE_VERSION); + if (!Strings.isNullOrEmpty(hiveVersion)) { + copiedProps.remove(HMSProperties.HIVE_VERSION); + hiveProperties.put(HMSProperties.HIVE_VERSION, hiveVersion); + } // check auth type String authType = copiedProps.get(HdfsResource.HADOOP_SECURITY_AUTHENTICATION); diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 885e932a86..30837fb685 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -2651,6 +2651,9 @@ public class InternalCatalog implements CatalogIf { HiveConf hiveConf = new HiveConf(); hiveConf.set(HMSProperties.HIVE_METASTORE_URIS, hiveTable.getHiveProperties().get(HMSProperties.HIVE_METASTORE_URIS)); + if (!Strings.isNullOrEmpty(hiveTable.getHiveProperties().get(HMSProperties.HIVE_VERSION))) { + hiveConf.set(HMSProperties.HIVE_VERSION, hiveTable.getHiveProperties().get(HMSProperties.HIVE_VERSION)); + } PooledHiveMetaStoreClient client = new PooledHiveMetaStoreClient(hiveConf, 1); if (!client.tableExists(hiveTable.getHiveDb(), hiveTable.getHiveTable())) { throw new DdlException(String.format("Table [%s] dose not exist in Hive.", hiveTable.getHiveDbTable())); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/HiveTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/HiveTableTest.java index 983cd2736e..abfcc68790 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/HiveTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/HiveTableTest.java @@ -18,6 +18,7 @@ package org.apache.doris.catalog; import org.apache.doris.common.DdlException; +import org.apache.doris.datasource.property.constants.HMSProperties; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -77,4 +78,11 @@ public class HiveTableTest { new HiveTable(1000, "hive_table", columns, properties); Assert.fail("No exception throws."); } + + @Test() + public void testVersion() throws DdlException { + properties.put(HMSProperties.HIVE_VERSION, "2.1.2"); + HiveTable table = new HiveTable(1000, "hive_table", columns, properties); + Assert.assertEquals("2.1.2", table.getHiveProperties().get(HMSProperties.HIVE_VERSION)); + } }