You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/01/05 23:44:14 UTC

incubator-atlas git commit: ATLAS-1419: fix entity-update to set attribute value to null when null is explicitly provided

Repository: incubator-atlas
Updated Branches:
  refs/heads/0.7-incubating 77ea77286 -> 2e5ecb128


ATLAS-1419: fix entity-update to set attribute value to null when null is explicitly provided

Signed-off-by: Madhan Neethiraj <ma...@apache.org>


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

Branch: refs/heads/0.7-incubating
Commit: 2e5ecb128d4be9d7b227a385fd750311dcca8c27
Parents: 77ea772
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Wed Jan 4 23:36:05 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Thu Jan 5 13:29:19 2017 -0800

----------------------------------------------------------------------
 release-log.txt                                 |  1 +
 .../graph/TypedInstanceToGraphMapper.java       | 35 +++++++------------
 .../atlas/services/DefaultMetadataService.java  | 36 ++++++++++----------
 3 files changed, 31 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/2e5ecb12/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index b226eca..f3f7c33 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -32,6 +32,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)
 
 ALL CHANGES:
+ATLAS-1419 fix entity-update to set attribute value to null when null is explicitly provided (sarath.kum4r@gmail.com via mneethiraj)
 ATLAS-1427 Support an option to exclude protocols in SSL mode (nixonrodrigues via mneethiraj)
 ATLAS-1424 Avoid stack-trace in REST API error response (nixonrodrigues via mneethiraj)
 ATLAS-1420 use ATLASSESSIONID as cookie name instead of JSESSIONID (nixonrodrigues via mneethiraj)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/2e5ecb12/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
index aff21af..93fd69f 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
@@ -45,6 +45,8 @@ import org.apache.atlas.typesystem.types.TraitType;
 import org.apache.atlas.typesystem.types.TypeSystem;
 import org.apache.atlas.typesystem.types.TypeUtils;
 import org.apache.atlas.utils.MD5Utils;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -320,29 +322,21 @@ public final class TypedInstanceToGraphMapper {
                 attributeInfo.name, string(instanceVertex));
 
         List newElements = (List) typedInstance.get(attributeInfo.name);
-        boolean newAttributeEmpty = (newElements == null || newElements.isEmpty());
-
-        if (newAttributeEmpty && operation != Operation.UPDATE_FULL) {
-            return;
-        }
 
         String propertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo);
         List<String> currentElements = GraphHelper.getProperty(instanceVertex, propertyName);
         IDataType elementType = ((DataTypes.ArrayType) attributeInfo.dataType()).getElemType();
         List<Object> newElementsCreated = new ArrayList<>();
 
-        if (!newAttributeEmpty) {
-            if (newElements != null && !newElements.isEmpty()) {
-                int index = 0;
-                for (; index < newElements.size(); index++) {
-                    String currentElement = (currentElements != null && index < currentElements.size()) ?
-                            currentElements.get(index) : null;
-                    LOG.debug("Adding/updating element at position {}, current element {}, new element {}", index,
-                            currentElement, newElements.get(index));
-                    Object newEntry = addOrUpdateCollectionEntry(instanceVertex, attributeInfo, elementType,
-                            newElements.get(index), currentElement, propertyName, operation);
-                    newElementsCreated.add(newEntry);
-                }
+        if (CollectionUtils.isNotEmpty(newElements)) {
+            for (int index = 0; index < newElements.size(); index++) {
+                String currentElement = (currentElements != null && index < currentElements.size()) ?
+                        currentElements.get(index) : null;
+                LOG.debug("Adding/updating element at position {}, current element {}, new element {}", index,
+                        currentElement, newElements.get(index));
+                Object newEntry = addOrUpdateCollectionEntry(instanceVertex, attributeInfo, elementType,
+                        newElements.get(index), currentElement, propertyName, operation);
+                newElementsCreated.add(newEntry);
             }
         }
 
@@ -397,11 +391,6 @@ public final class TypedInstanceToGraphMapper {
         @SuppressWarnings("unchecked") Map<Object, Object> newAttribute =
                 (Map<Object, Object>) typedInstance.get(attributeInfo.name);
 
-        boolean newAttributeEmpty = (newAttribute == null || newAttribute.isEmpty());
-        if (newAttributeEmpty && operation != Operation.UPDATE_FULL) {
-            return;
-        }
-
         IDataType elementType = ((DataTypes.MapType) attributeInfo.dataType()).getValueType();
         String propertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo);
 
@@ -417,7 +406,7 @@ public final class TypedInstanceToGraphMapper {
             }
         }
 
-        if (!newAttributeEmpty) {
+        if (MapUtils.isNotEmpty(newAttribute)) {
             for (Map.Entry entry : newAttribute.entrySet()) {
                 String keyStr = entry.getKey().toString();
                 String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(propertyName, keyStr);

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/2e5ecb12/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
index 3550492..e9ac600 100755
--- a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
+++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
@@ -519,30 +519,30 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
 
             DataTypes.TypeCategory attrTypeCategory = attributeInfo.dataType().getTypeCategory();
             Object value = updatedEntity.get(attributeName);
-            if (value != null) {
-                switch (attrTypeCategory) {
-                    case CLASS:
+            switch (attrTypeCategory) {
+                case CLASS:
+                    if (value != null) {
                         if (value instanceof Referenceable) {
                             newInstance.set(attributeName, value);
                         } else {
                             Id id = new Id((String) value, 0, attributeInfo.dataType().getName());
                             newInstance.set(attributeName, id);
                         }
-                        break;
-
-                    case ENUM:
-                    case PRIMITIVE:
-                    case ARRAY:
-                    case STRUCT:
-                    case MAP:
-                        newInstance.set(attributeName, value);
-                        break;
-
-                    case TRAIT:
-                        //TODO - handle trait updates as well?
-                    default:
-                        throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
-                }
+                    }
+                    break;
+
+                case ENUM:
+                case PRIMITIVE:
+                case ARRAY:
+                case STRUCT:
+                case MAP:
+                    newInstance.set(attributeName, value);
+                    break;
+
+                case TRAIT:
+                    //TODO - handle trait updates as well?
+                default:
+                    throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
             }
         }