Skip to content

Commit

Permalink
[fix][fe] support set hive version when create hive external table
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCooker17 committed Jun 9, 2023
1 parent f0777f7 commit 24d35ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Expand Up @@ -106,6 +106,12 @@ private void validate(Map<String, String> properties) throws DdlException {
}
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);
Expand Down
Expand Up @@ -2454,6 +2454,9 @@ private void createHiveTable(Database db, CreateTableStmt stmt) throws DdlExcept
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()));
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -77,4 +78,11 @@ public void testNoHiveMetastoreUris() throws DdlException {
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));
}
}

0 comments on commit 24d35ac

Please sign in to comment.