From b44f60edb6f20225b308fb4324cf30fa1c34fc47 Mon Sep 17 00:00:00 2001 From: srinivasan Date: Thu, 18 Jun 2015 22:38:36 +0530 Subject: [PATCH 1/2] Added support for external tables --- .../org/apache/kylin/dict/lookup/HiveTable.java | 22 ++++++++++++++----- 1 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dictionary/src/main/java/org/apache/kylin/dict/lookup/HiveTable.java b/dictionary/src/main/java/org/apache/kylin/dict/lookup/HiveTable.java index ae224ac..b57cad7 100644 --- a/dictionary/src/main/java/org/apache/kylin/dict/lookup/HiveTable.java +++ b/dictionary/src/main/java/org/apache/kylin/dict/lookup/HiveTable.java @@ -48,6 +48,8 @@ public class HiveTable implements ReadableTable { private int nColumns; private String hdfsLocation; private FileTable fileTable; + private HiveClient hiveClient; + private boolean needFilePath; public HiveTable(MetadataManager metaMgr, String table) { TableDesc tableDesc = metaMgr.getTableDesc(table); @@ -73,19 +75,19 @@ public class HiveTable implements ReadableTable { private FileTable getFileTable() throws IOException { if (fileTable == null) { - fileTable = new FileTable(getHDFSLocation(true), nColumns); + fileTable = new FileTable(getHDFSLocation(), nColumns); } return fileTable; } - public String getHDFSLocation(boolean needFilePath) throws IOException { + public String getHDFSLocation() throws IOException { if (hdfsLocation == null) { - hdfsLocation = computeHDFSLocation(needFilePath); + hdfsLocation = computeHDFSLocation(); } return hdfsLocation; } - private String computeHDFSLocation(boolean needFilePath) throws IOException { + private String computeHDFSLocation() throws IOException { String override = KylinConfig.getInstanceFromEnv().getOverrideHiveTableLocation(hiveTable); if (override != null) { @@ -95,8 +97,8 @@ public class HiveTable implements ReadableTable { String hdfsDir = null; try { - HiveClient hiveClient = new HiveClient(); - hdfsDir = hiveClient.getHiveTableLocation(database, hiveTable); + hdfsDir = getHiveClient().getHiveTableLocation(database, hiveTable); + needFilePath = getHiveClient().isManagedTable(database, hiveTable); } catch (Exception e) { e.printStackTrace(); throw new IOException(e); @@ -129,4 +131,12 @@ public class HiveTable implements ReadableTable { return "hive: database=[" + database + "], table=[" + hiveTable + "]"; } + public HiveClient getHiveClient() { + + if (hiveClient == null) { + hiveClient = new HiveClient(); + } + return hiveClient; + } + } -- 1.7.1 From 0a08266797217af04400298dd458819bcc1e3d49 Mon Sep 17 00:00:00 2001 From: Srinivasan Date: Thu, 18 Jun 2015 22:40:37 +0530 Subject: [PATCH 2/2] Added method to find hive table type --- .../org/apache/kylin/common/util/HiveClient.java | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/common/src/main/java/org/apache/kylin/common/util/HiveClient.java b/common/src/main/java/org/apache/kylin/common/util/HiveClient.java index cfeea31..d832b15 100644 --- a/common/src/main/java/org/apache/kylin/common/util/HiveClient.java +++ b/common/src/main/java/org/apache/kylin/common/util/HiveClient.java @@ -44,6 +44,7 @@ public class HiveClient { protected HiveConf hiveConf = null; protected Driver driver = null; protected HiveMetaStoreClient metaStoreClient = null; + protected String type; public HiveClient() { hiveConf = new HiveConf(HiveClient.class); @@ -155,4 +156,17 @@ public class HiveClient { return result; } + /** + * + * @param database + * @param tableName + * @throws Exception + */ + + public boolean isManagedTable(String database, String tableName) throws Exception{ + + return getMetaStoreClient().getTable(database, tableName).getTableType().toLowerCase().startsWith("managed"); + + } + } -- 1.7.1