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

Signed-off-by: Sarath Subramanian <ssubramanian@hortonworks.com>
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 @@
     }
 
     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 @@
             entity.getRelationshipAttributes().clear();
         }
     }
+
+    private boolean isTableWithDatabaseName(String tableName) {
+        boolean ret = false;
+        if (tableName.contains(".")) {
+            ret = true;
+        }
+        return ret;
+    }
 }