Commit 12ca5c97 by rmani Committed by Sarath Subramanian

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

parent 59ae59db
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment