Repository: atlas Updated Branches: refs/heads/branch-1.0 33a9ae1f9 -> 84c66058e
ATLAS-2785: Import Hive script should handle table name with database in -t option Signed-off-by: Sarath Subramanian <[email protected]> (cherry picked from commit 12ca5c97aa3d8ef0b35fb32e4f7f44cedaf1d620) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/84c66058 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/84c66058 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/84c66058 Branch: refs/heads/branch-1.0 Commit: 84c66058ef47366bbdf2fab4d50e8264dff483ec Parents: 33a9ae1 Author: rmani <[email protected]> Authored: Tue Jul 10 15:25:17 2018 -0700 Committer: Sarath Subramanian <[email protected]> Committed: Tue Jul 10 15:25:50 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/84c66058/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; + } }
