sarathkumarsubramanian commented on a change in pull request #37: 
ATLAS-2933:Empty array attributes are returned as null instead of an empty list
URL: https://github.com/apache/atlas/pull/37#discussion_r269260617
 
 

 ##########
 File path: 
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
 ##########
 @@ -947,52 +947,63 @@ private AtlasEdge 
mapObjectIdValueUsingRelationship(AttributeMutationContext ctx
         boolean             isReference = isReference(mapType.getValueType());
         boolean             isSoftReference = 
ctx.getAttribute().getAttributeDef().isSoftReferenced();
 
-        if (MapUtils.isNotEmpty(newVal)) {
-            String propertyName = ctx.getVertexProperty();
+        boolean isNewValNull = newVal == null;
 
-            if (isReference) {
-                for (Map.Entry<Object, Object> entry : newVal.entrySet()) {
-                    String    key          = entry.getKey().toString();
-                    AtlasEdge existingEdge = isSoftReference ? null : 
getEdgeIfExists(mapType, currentMap, key);
+        if (isNewValNull) {
+            newVal = new HashMap<>();
+        }
 
-                    AttributeMutationContext mapCtx =  new 
AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), attribute, 
entry.getValue(),
-                                                                               
      propertyName, mapType.getValueType(), existingEdge);
-                    // Add/Update/Remove property value
-                    Object newEntry = mapCollectionElementsToVertex(mapCtx, 
context);
+        String propertyName = ctx.getVertexProperty();
 
-                    if (!isSoftReference && newEntry instanceof AtlasEdge) {
-                        AtlasEdge edge = (AtlasEdge) newEntry;
+        if (isReference) {
+            for (Map.Entry<Object, Object> entry : newVal.entrySet()) {
+                String    key          = entry.getKey().toString();
+                AtlasEdge existingEdge = isSoftReference ? null : 
getEdgeIfExists(mapType, currentMap, key);
 
-                        edge.setProperty(ATTRIBUTE_KEY_PROPERTY_KEY, key);
+                AttributeMutationContext mapCtx =  new 
AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), attribute, 
entry.getValue(),
+                                                                               
  propertyName, mapType.getValueType(), existingEdge);
+                // Add/Update/Remove property value
+                Object newEntry = mapCollectionElementsToVertex(mapCtx, 
context);
 
-                        // If value type indicates this attribute is a 
reference, and the attribute has an inverse reference attribute,
-                        // update the inverse reference value.
-                        AtlasAttribute inverseRefAttribute = 
attribute.getInverseRefAttribute();
+                if (!isSoftReference && newEntry instanceof AtlasEdge) {
+                    AtlasEdge edge = (AtlasEdge) newEntry;
 
-                        if (inverseRefAttribute != null) {
-                            addInverseReference(context, inverseRefAttribute, 
edge, getRelationshipAttributes(ctx.getValue()));
-                        }
+                    edge.setProperty(ATTRIBUTE_KEY_PROPERTY_KEY, key);
 
-                        updateInConsistentOwnedMapVertices(ctx, mapType, 
newEntry);
+                    // If value type indicates this attribute is a reference, 
and the attribute has an inverse reference attribute,
+                    // update the inverse reference value.
+                    AtlasAttribute inverseRefAttribute = 
attribute.getInverseRefAttribute();
 
-                        newMap.put(key, newEntry);
+                    if (inverseRefAttribute != null) {
+                        addInverseReference(context, inverseRefAttribute, 
edge, getRelationshipAttributes(ctx.getValue()));
                     }
 
-                    if (isSoftReference) {
-                        newMap.put(key, newEntry);
-                    }
+                    updateInConsistentOwnedMapVertices(ctx, mapType, newEntry);
+
+                    newMap.put(key, newEntry);
+                }
+
+                if (isSoftReference) {
+                    newMap.put(key, newEntry);
                 }
+            }
 
-                Map<String, Object> finalMap = 
removeUnusedMapEntries(attribute, ctx.getReferringVertex(), currentMap, newMap);
-                newMap.putAll(finalMap);
+            Map<String, Object> finalMap = removeUnusedMapEntries(attribute, 
ctx.getReferringVertex(), currentMap, newMap);
+            newMap.putAll(finalMap);
+        } else {
+            // primitive type map
+            if (isNewValNull) {
+                ctx.getReferringVertex().setProperty(propertyName, null);
             } else {
-                // primitive type map
                 ctx.getReferringVertex().setProperty(propertyName, new 
HashMap<>(newVal));
-
-                newVal.forEach((key, value) -> newMap.put(key.toString(), 
value));
             }
+            newVal.forEach((key, value) -> newMap.put(key.toString(), value));
+        }
 
-            if (isSoftReference) {
+        if (isSoftReference) {
+            if (isNewValNull) {
+                ctx.getReferringVertex().setProperty(propertyName,null);
 
 Review comment:
   => ctx.getReferringVertex().removeProperty(propertyName);

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to