Repository: atlas
Updated Branches:
  refs/heads/branch-0.8 27fad9f4a -> 1a02dfe56


ATLAS-2581: V2 Hive hook notifications - incorrect location for sd after moving 
table to a different database

(cherry picked from commit fab76a4ea7b75167898577dfe02827b25df7a27a)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/1a02dfe5
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/1a02dfe5
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/1a02dfe5

Branch: refs/heads/branch-0.8
Commit: 1a02dfe5642863ffe54a3903fdd499adc19099c4
Parents: 27fad9f
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Tue Apr 17 15:10:42 2018 -0700
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Tue Apr 17 18:43:38 2018 -0700

----------------------------------------------------------------------
 .../hive/hook/events/AlterTableRename.java      | 53 +++++++++++++-------
 .../atlas/util/AtlasGremlin2QueryProvider.java  |  2 +-
 2 files changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/1a02dfe5/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTableRename.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTableRename.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTableRename.java
index d5b9fc3..6ced340 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTableRename.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/AlterTableRename.java
@@ -72,6 +72,8 @@ public class AlterTableRename extends BaseHiveEvent {
                         continue;
                     }
 
+                    newTable = getHive().getTable(newTable.getDbName(), 
newTable.getTableName());
+
                     break;
                 }
             }
@@ -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
         ret.add(new EntityUpdateRequestV2(getUserName(), new 
AtlasEntitiesWithExtInfo(oldTableEntity)));
 
+        AtlasEntityWithExtInfo renamedTableEntity = toTableEntity(newTable);
+
         // 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_PARTITION_KEYS), 
oldTableEntity, newTableQualifiedName, ret);
-        renameStorageDesc((AtlasObjectId) 
oldTableEntity.getEntity().getAttribute(ATTRIBUTE_STORAGEDESC), oldTableEntity, 
newTableQualifiedName, ret);
+        renameColumns((List<AtlasObjectId>) 
oldTableEntity.getEntity().getAttribute(ATTRIBUTE_COLUMNS), oldTableEntity, 
renamedTableQualifiedName, ret);
+        renameColumns((List<AtlasObjectId>) 
oldTableEntity.getEntity().getAttribute(ATTRIBUTE_PARTITION_KEYS), 
oldTableEntity, renamedTableQualifiedName, ret);
+        renameStorageDesc(oldTableEntity, renamedTableEntity, ret);
 
-        // update qualifiedName and other attributes (like params - which 
include lastModifiedTime, lastModifiedBy) of the table
-        AtlasEntityWithExtInfo newTableEntity = toTableEntity(newTable);
+        // remove columns, partitionKeys and storageDesc - as they have 
already been updated above
+        removeAttribute(renamedTableEntity, ATTRIBUTE_COLUMNS);
+        removeAttribute(renamedTableEntity, ATTRIBUTE_PARTITION_KEYS);
+        removeAttribute(renamedTableEntity, ATTRIBUTE_STORAGEDESC);
 
         // set previous name as the alias
-        newTableEntity.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);
+        renamedTableEntity.getEntity().setAttribute(ATTRIBUTE_ALIASES, 
Collections.singletonList(oldTable.getTableName()));
 
         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));
 
@@ -127,11 +129,14 @@ public class AlterTableRename extends BaseHiveEvent {
         }
     }
 
-    private void renameStorageDesc(AtlasObjectId sdId, AtlasEntityExtInfo 
oldEntityExtInfo, String newTableQualifiedName, List<HookNotificationMessage> 
notifications) {
-        if (sdId != null) {
-            AtlasEntity   oldSd   = oldEntityExtInfo.getEntity(sdId.getGuid());
+    private void renameStorageDesc(AtlasEntityWithExtInfo oldEntityExtInfo, 
AtlasEntityWithExtInfo newEntityExtInfo, List<HookNotificationMessage> 
notifications) {
+        AtlasEntity oldSd = getStorageDescEntity(oldEntityExtInfo);
+        AtlasEntity newSd = getStorageDescEntity(newEntityExtInfo);
+
+        if (oldSd != null && newSd != null) {
             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.getAttributes().remove(ATTRIBUTE_TABLE);
 
             notifications.add(new EntityPartialUpdateRequestV2(getUserName(), 
oldSdId, new AtlasEntityWithExtInfo(newSd)));
         }
@@ -156,7 +161,17 @@ public class AlterTableRename extends BaseHiveEvent {
         }
     }
 
-    private String getStorageDescQualifiedName(String tblQualifiedName) {
-        return tblQualifiedName + "_storage";
+    private AtlasEntity getStorageDescEntity(AtlasEntityWithExtInfo 
tableEntity) {
+        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;
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/1a02dfe5/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
 
b/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
index 5cacbfd..a68e3c3 100644
--- 
a/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
+++ 
b/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
@@ -78,7 +78,7 @@ public class AtlasGremlin2QueryProvider extends 
AtlasGremlinQueryProvider {
             case GUID_PREFIX_FILTER:
                 return ".filter{it.'__guid'.matches(guid)}";
             case RELATIONSHIP_SEARCH:
-                return "g.V('__guid', guid).both(relation).has('__state', 
T.in, states)";
+                return "g.V('__guid', 
guid).copySplit(_().outE(relation).has('__state', 'ACTIVE').inV(), 
_().inE(relation).has('__state', 'ACTIVE').outV()).fairMerge().has('__state', 
T.in, states)";
             case RELATIONSHIP_SEARCH_ASCENDING_SORT:
                 return ".order{it.a.getProperty(sortAttributeName) <=> 
it.b.getProperty(sortAttributeName)}";
             case RELATIONSHIP_SEARCH_DESCENDING_SORT:

Reply via email to