Commit 6c49542b by Madhan Neethiraj

ATLAS-2581: V2 Hive hook notifications - incorrect location for sd after moving…

ATLAS-2581: V2 Hive hook notifications - incorrect location for sd after moving table to a different database
parent cabc1e55
...@@ -72,6 +72,8 @@ public class AlterTableRename extends BaseHiveEvent { ...@@ -72,6 +72,8 @@ public class AlterTableRename extends BaseHiveEvent {
continue; continue;
} }
newTable = getHive().getTable(newTable.getDbName(), newTable.getTableName());
break; break;
} }
} }
...@@ -88,27 +90,27 @@ public class AlterTableRename extends BaseHiveEvent { ...@@ -88,27 +90,27 @@ public class AlterTableRename extends BaseHiveEvent {
// first update with oldTable info, so that the table will be created if it is not present in Atlas // first update with oldTable info, so that the table will be created if it is not present in Atlas
ret.add(new EntityUpdateRequestV2(getUserName(), new AtlasEntitiesWithExtInfo(oldTableEntity))); ret.add(new EntityUpdateRequestV2(getUserName(), new AtlasEntitiesWithExtInfo(oldTableEntity)));
AtlasEntityWithExtInfo renamedTableEntity = toTableEntity(newTable);
// update qualifiedName for all columns, partitionKeys, storageDesc // update qualifiedName for all columns, partitionKeys, storageDesc
String newTableQualifiedName = getQualifiedName(newTable); String renamedTableQualifiedName = (String) renamedTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME);
renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_COLUMNS), oldTableEntity, newTableQualifiedName, ret); renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_COLUMNS), oldTableEntity, renamedTableQualifiedName, ret);
renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_PARTITION_KEYS), oldTableEntity, newTableQualifiedName, ret); renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_PARTITION_KEYS), oldTableEntity, renamedTableQualifiedName, ret);
renameStorageDesc((AtlasObjectId) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_STORAGEDESC), oldTableEntity, newTableQualifiedName, ret); renameStorageDesc(oldTableEntity, renamedTableEntity, ret);
// update qualifiedName and other attributes (like params - which include lastModifiedTime, lastModifiedBy) of the table // remove columns, partitionKeys and storageDesc - as they have already been updated above
AtlasEntityWithExtInfo newTableEntity = toTableEntity(newTable); removeAttribute(renamedTableEntity, ATTRIBUTE_COLUMNS);
removeAttribute(renamedTableEntity, ATTRIBUTE_PARTITION_KEYS);
removeAttribute(renamedTableEntity, ATTRIBUTE_STORAGEDESC);
// set previous name as the alias // set previous name as the alias
newTableEntity.getEntity().setAttribute(ATTRIBUTE_ALIASES, Collections.singletonList(oldTable.getTableName())); renamedTableEntity.getEntity().setAttribute(ATTRIBUTE_ALIASES, Collections.singletonList(oldTable.getTableName()));
// remove columns, partitionKeys and storageDesc - as they have already been updated above
removeAttribute(newTableEntity, ATTRIBUTE_COLUMNS);
removeAttribute(newTableEntity, ATTRIBUTE_PARTITION_KEYS);
removeAttribute(newTableEntity, ATTRIBUTE_STORAGEDESC);
AtlasObjectId oldTableId = new AtlasObjectId(oldTableEntity.getEntity().getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME)); AtlasObjectId oldTableId = new AtlasObjectId(oldTableEntity.getEntity().getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME));
ret.add(new EntityPartialUpdateRequestV2(getUserName(), oldTableId, newTableEntity)); // update qualifiedName and other attributes (like params - which include lastModifiedTime, lastModifiedBy) of the table
ret.add(new EntityPartialUpdateRequestV2(getUserName(), oldTableId, renamedTableEntity));
context.removeFromKnownTable((String) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME)); context.removeFromKnownTable((String) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME));
...@@ -127,11 +129,14 @@ public class AlterTableRename extends BaseHiveEvent { ...@@ -127,11 +129,14 @@ public class AlterTableRename extends BaseHiveEvent {
} }
} }
private void renameStorageDesc(AtlasObjectId sdId, AtlasEntityExtInfo oldEntityExtInfo, String newTableQualifiedName, List<HookNotification> notifications) { private void renameStorageDesc(AtlasEntityWithExtInfo oldEntityExtInfo, AtlasEntityWithExtInfo newEntityExtInfo, List<HookNotification> notifications) {
if (sdId != null) { AtlasEntity oldSd = getStorageDescEntity(oldEntityExtInfo);
AtlasEntity oldSd = oldEntityExtInfo.getEntity(sdId.getGuid()); AtlasEntity newSd = getStorageDescEntity(newEntityExtInfo);
if (oldSd != null && newSd != null) {
AtlasObjectId oldSdId = new AtlasObjectId(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldSd.getAttribute(ATTRIBUTE_QUALIFIED_NAME)); AtlasObjectId oldSdId = new AtlasObjectId(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldSd.getAttribute(ATTRIBUTE_QUALIFIED_NAME));
AtlasEntity newSd = new AtlasEntity(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, getStorageDescQualifiedName(newTableQualifiedName));
newSd.removeAttribute(ATTRIBUTE_TABLE);
notifications.add(new EntityPartialUpdateRequestV2(getUserName(), oldSdId, new AtlasEntityWithExtInfo(newSd))); notifications.add(new EntityPartialUpdateRequestV2(getUserName(), oldSdId, new AtlasEntityWithExtInfo(newSd)));
} }
...@@ -156,7 +161,17 @@ public class AlterTableRename extends BaseHiveEvent { ...@@ -156,7 +161,17 @@ public class AlterTableRename extends BaseHiveEvent {
} }
} }
private String getStorageDescQualifiedName(String tblQualifiedName) { private AtlasEntity getStorageDescEntity(AtlasEntityWithExtInfo tableEntity) {
return tblQualifiedName + "_storage"; AtlasEntity ret = null;
if (tableEntity != null && tableEntity.getEntity() != null) {
Object attrSdId = tableEntity.getEntity().getAttribute(ATTRIBUTE_STORAGEDESC);
if (attrSdId instanceof AtlasObjectId) {
ret = tableEntity.getReferredEntity(((AtlasObjectId) attrSdId).getGuid());
}
}
return ret;
} }
} }
...@@ -52,7 +52,7 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider { ...@@ -52,7 +52,7 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider {
case TO_RANGE_LIST: case TO_RANGE_LIST:
return ".range(startIdx, endIdx).toList()"; return ".range(startIdx, endIdx).toList()";
case RELATIONSHIP_SEARCH: case RELATIONSHIP_SEARCH:
return "g.V().has('__guid', guid).both(relation).has('__state', within(states))"; return "g.V().has('__guid', guid).bothE(relation).has('__state', within(states)).otherV().has('__state', within(states))";
case RELATIONSHIP_SEARCH_ASCENDING_SORT: case RELATIONSHIP_SEARCH_ASCENDING_SORT:
return ".order().by(sortAttributeName, incr)"; return ".order().by(sortAttributeName, incr)";
case RELATIONSHIP_SEARCH_DESCENDING_SORT: case RELATIONSHIP_SEARCH_DESCENDING_SORT:
......
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