Commit daf812aa by Suma Shivaprasad

ATLAS-594 alter table rename doesnt work across databases ( sumasai via shwethags)

parent f7146ede
...@@ -406,10 +406,9 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext { ...@@ -406,10 +406,9 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext {
for (WriteEntity writeEntity : event.getOutputs()) { for (WriteEntity writeEntity : event.getOutputs()) {
if (writeEntity.getType() == Entity.Type.TABLE) { if (writeEntity.getType() == Entity.Type.TABLE) {
Table newTable = writeEntity.getTable(); Table newTable = writeEntity.getTable();
if (newTable.getDbName().equals(oldTable.getDbName()) && !newTable.getTableName() //Hive sends with both old and new table names in the outputs which is weird. So skipping that with the below check
.equals(oldTable.getTableName())) { if (!newTable.getDbName().equals(oldTable.getDbName()) || !newTable.getTableName().equals(oldTable.getTableName())) {
//Create/update old table entity - create new entity with oldQFNme and tableName
//Create/update old table entity - create new entity and replace id
Referenceable tableEntity = createOrUpdateEntities(dgiBridge, event.getUser(), writeEntity); Referenceable tableEntity = createOrUpdateEntities(dgiBridge, event.getUser(), writeEntity);
String oldQualifiedName = dgiBridge.getTableQualifiedName(dgiBridge.getClusterName(), String oldQualifiedName = dgiBridge.getTableQualifiedName(dgiBridge.getClusterName(),
oldTable.getDbName(), oldTable.getTableName()); oldTable.getDbName(), oldTable.getTableName());
...@@ -419,6 +418,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext { ...@@ -419,6 +418,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext {
String newQualifiedName = dgiBridge.getTableQualifiedName(dgiBridge.getClusterName(), String newQualifiedName = dgiBridge.getTableQualifiedName(dgiBridge.getClusterName(),
newTable.getDbName(), newTable.getTableName()); newTable.getDbName(), newTable.getTableName());
//Replace entity with new name
Referenceable newEntity = new Referenceable(HiveDataTypes.HIVE_TABLE.getName()); Referenceable newEntity = new Referenceable(HiveDataTypes.HIVE_TABLE.getName());
newEntity.set(HiveDataModelGenerator.NAME, newQualifiedName); newEntity.set(HiveDataModelGenerator.NAME, newQualifiedName);
newEntity.set(HiveDataModelGenerator.TABLE_NAME, newTable.getTableName().toLowerCase()); newEntity.set(HiveDataModelGenerator.TABLE_NAME, newTable.getTableName().toLowerCase());
......
...@@ -557,11 +557,15 @@ public class HiveHookIT { ...@@ -557,11 +557,15 @@ public class HiveHookIT {
@Test @Test
public void testAlterTableRename() throws Exception { public void testAlterTableRename() throws Exception {
String tableName = createTable(); String tableName = createTable();
String newName = tableName(); final String newDBName = createDatabase();
String query = "alter table " + tableName + " rename to " + newName; assertTableIsRegistered(DEFAULT_DB, tableName);
assertDatabaseIsRegistered(newDBName);
String newTableName = tableName();
String query = String.format("alter table %s rename to %s", DEFAULT_DB + "." + tableName, newDBName + "." + newTableName);
runCommand(query); runCommand(query);
assertTableIsRegistered(DEFAULT_DB, newName); assertTableIsRegistered(newDBName, newTableName);
assertTableIsNotRegistered(DEFAULT_DB, tableName); assertTableIsNotRegistered(DEFAULT_DB, tableName);
} }
......
...@@ -15,6 +15,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset ...@@ -15,6 +15,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags) ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES: ALL CHANGES:
ATLAS-594 alter table rename doesnt work across databases (sumasai via shwethags)
ATLAS-586 While updating the multiple attributes, Atlas returns the response with escape characters (dkantor via shwethags) ATLAS-586 While updating the multiple attributes, Atlas returns the response with escape characters (dkantor via shwethags)
ATLAS-582 Move Atlas UI to use backboneJS (kevalbhatt18 via shwethags) ATLAS-582 Move Atlas UI to use backboneJS (kevalbhatt18 via shwethags)
ATLAS-540 API to retrieve entity version events (shwethags) ATLAS-540 API to retrieve entity version events (shwethags)
......
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