This is an automated email from the ASF dual-hosted git repository. nic pushed a commit to branch 3.0.x in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 918b8a149df23d2339881b45e335735677599aee Author: XiaoxiangYu <hit_la...@126.com> AuthorDate: Mon Jan 13 10:42:10 2020 +0800 Fix for KYLIN-4206 --- .../kylin/source/hive/HiveMetaStoreClientFactory.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetaStoreClientFactory.java b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetaStoreClientFactory.java index 984623f..ceadacd 100644 --- a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetaStoreClientFactory.java +++ b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetaStoreClientFactory.java @@ -22,10 +22,10 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hive.hcatalog.common.HCatUtil; import org.apache.kylin.common.KylinConfig; import java.io.IOException; +import java.lang.reflect.Method; public class HiveMetaStoreClientFactory { @@ -42,12 +42,21 @@ public class HiveMetaStoreClientFactory { */ public static IMetaStoreClient getHiveMetaStoreClient(HiveConf hiveConf) throws MetaException, IOException { IMetaStoreClient metaStoreClient = null; - if ("hcatalog".equals(KylinConfig.getInstanceFromEnv().getHiveMetaDataType())) { + String hiveMetadataOption = KylinConfig.getInstanceFromEnv().getHiveMetaDataType(); + if ("hcatalog".equals(hiveMetadataOption)) { metaStoreClient = new HiveMetaStoreClient(hiveConf); - } else if ("gluecatalog".equals(KylinConfig.getInstanceFromEnv().getHiveMetaDataType())) { - metaStoreClient = HCatUtil.getHiveMetastoreClient(hiveConf); + } else if ("gluecatalog".equals(hiveMetadataOption)) { + // getHiveMetastoreClient is not available in CDH profile + try { + Class<?> clazz = Class.forName("org.apache.hive.hcatalog.common.HCatUtil"); + Method getHiveMetastoreClientMethod = clazz.getDeclaredMethod("getHiveMetastoreClient"); + metaStoreClient = (IMetaStoreClient) getHiveMetastoreClientMethod.invoke(null, hiveConf); + } catch (Exception exp) { + throw new IllegalStateException("Unable to create MetaStoreClient for " + hiveMetadataOption, exp); + } + } else { + throw new IllegalArgumentException(hiveMetadataOption + " is not a good option."); } return metaStoreClient; } - }