Skip to content

Commit 0eb0644

Browse files
authored
Merge pull request #2356 from atlanhq/plt-1891-struct-diff
fix: fix for array and the maps
2 parents 115c16d + 45c1708 commit 0eb0644

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityComparator.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.atlas.repository.store.graph.v2;
2020

2121
import org.apache.atlas.exception.AtlasBaseException;
22+
import org.apache.atlas.model.TypeCategory;
2223
import org.apache.atlas.model.instance.AtlasClassification;
2324
import org.apache.atlas.model.instance.AtlasEntity;
2425
import org.apache.atlas.repository.graphdb.AtlasVertex;
@@ -28,6 +29,7 @@
2829
import org.apache.atlas.utils.AtlasEntityUtil;
2930
import org.apache.commons.collections.MapUtils;
3031

32+
import java.util.ArrayList;
3133
import java.util.List;
3234
import java.util.Map;
3335
import java.util.Objects;
@@ -81,7 +83,28 @@ private AtlasEntityDiffResult getDiffResult(AtlasEntity updatedEntity, AtlasEnti
8183
continue;
8284
}
8385

84-
Object newVal = entry.getValue();
86+
TypeCategory category = attribute.getAttributeType().getTypeCategory();
87+
boolean isDefaultValueNotNull = !attribute.getAttributeDef().getIsDefaultValueNull();
88+
Object newVal;
89+
90+
if (entry.getValue() == null && isDefaultValueNotNull) {
91+
switch (category) {
92+
case PRIMITIVE:
93+
newVal = attribute.getAttributeType().createDefaultValue();
94+
break;
95+
case ARRAY:
96+
newVal = new ArrayList<>();
97+
break;
98+
case MAP:
99+
newVal = MapUtils.EMPTY_MAP;
100+
break;
101+
default:
102+
newVal = entry.getValue();
103+
}
104+
} else {
105+
newVal = entry.getValue();
106+
}
107+
85108
Object currVal = (storedEntity != null) ? storedEntity.getAttribute(attrName) : entityRetriever.getEntityAttribute(storedVertex, attribute);
86109

87110
if (!attribute.getAttributeType().areEqualValues(currVal, newVal, guidRefMap)) {

0 commit comments

Comments
 (0)