You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2018/07/10 22:25:27 UTC

atlas git commit: ATLAS-2785: Import Hive script should handle table name with database in -t option

Repository: atlas
Updated Branches:
  refs/heads/master 59ae59dba -> 12ca5c97a


ATLAS-2785: Import Hive script should handle table name with database in -t option

Signed-off-by: Sarath Subramanian <ss...@hortonworks.com>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/12ca5c97
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/12ca5c97
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/12ca5c97

Branch: refs/heads/master
Commit: 12ca5c97aa3d8ef0b35fb32e4f7f44cedaf1d620
Parents: 59ae59d
Author: rmani <rm...@hortonworks.com>
Authored: Tue Jul 10 15:25:17 2018 -0700
Committer: Sarath Subramanian <ss...@hortonworks.com>
Committed: Tue Jul 10 15:25:17 2018 -0700

----------------------------------------------------------------------
 .../atlas/hive/bridge/HiveMetaStoreBridge.java  | 26 ++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/12ca5c97/addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java
----------------------------------------------------------------------
diff --git a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java
index 7b2fa67..dbb71ea 100755
--- a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java
+++ b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/bridge/HiveMetaStoreBridge.java
@@ -248,11 +248,25 @@ public class HiveMetaStoreBridge {
     }
 
     private void importDatabases(boolean failOnError, String databaseToImport, String tableToImport) throws Exception {
-        final List<String> databaseNames;
+        List<String> databaseNames = null;
 
-        if (StringUtils.isEmpty(databaseToImport)) {
+        if (StringUtils.isEmpty(databaseToImport) && StringUtils.isEmpty(tableToImport)) {
+            //when both database and table to import are empty, import all
             databaseNames = hiveClient.getAllDatabases();
+        } else if (StringUtils.isEmpty(databaseToImport) && StringUtils.isNotEmpty(tableToImport)) {
+            //when database is empty and table is not, then check table has database name in it and import that db and table
+            if (isTableWithDatabaseName(tableToImport)) {
+                String val[] = tableToImport.split("\\.");
+                if (val.length > 1) {
+                    databaseToImport = val[0];
+                    tableToImport = val[1];
+                }
+                databaseNames = hiveClient.getDatabasesByPattern(databaseToImport);
+            } else {
+                databaseNames = hiveClient.getAllDatabases();
+            }
         } else {
+            //when database to import has some value then, import that db and all table under it.
             databaseNames = hiveClient.getDatabasesByPattern(databaseToImport);
         }
 
@@ -919,4 +933,12 @@ public class HiveMetaStoreBridge {
             entity.getRelationshipAttributes().clear();
         }
     }
+
+    private boolean isTableWithDatabaseName(String tableName) {
+        boolean ret = false;
+        if (tableName.contains(".")) {
+            ret = true;
+        }
+        return ret;
+    }
 }