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 2018/01/13 00:02:06 UTC
atlas git commit: ATLAS-2325: fix to prevent duplicate elements in
SET type attributes
Repository: atlas
Updated Branches:
refs/heads/master 8c9d3da2c -> d5b438b5d
ATLAS-2325: fix to prevent duplicate elements in SET type attributes
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/d5b438b5
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/d5b438b5
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/d5b438b5
Branch: refs/heads/master
Commit: d5b438b5db08cc4ecff69912b425104cd7ecd924
Parents: 8c9d3da
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Mon Jan 8 21:11:04 2018 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Fri Jan 12 16:01:11 2018 -0800
----------------------------------------------------------------------
.../repository/store/graph/v1/EntityGraphMapper.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/atlas/blob/d5b438b5/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
index c6aa98a..7474a8a 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
@@ -33,6 +33,7 @@ import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graph.GraphHelper;
@@ -60,18 +61,19 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.*;
+import java.util.stream.Collectors;
import static org.apache.atlas.model.instance.AtlasRelatedObjectId.KEY_RELATIONSHIP_ATTRIBUTES;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.CREATE;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.DELETE;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.PARTIAL_UPDATE;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.UPDATE;
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality.SET;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
import static org.apache.atlas.repository.graph.GraphHelper.isRelationshipEdge;
import static org.apache.atlas.repository.graph.GraphHelper.string;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromVertex;
-import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.OUT;
@@ -808,6 +810,7 @@ public class EntityGraphMapper {
AtlasType elementType = arrType.getElementType();
boolean isReference = AtlasGraphUtilsV1.isReference(elementType);
AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute();
+ Cardinality cardinality = attribute.getAttributeDef().getCardinality();
List<Object> newElementsCreated = new ArrayList<>();
List<Object> currentElements;
@@ -818,6 +821,10 @@ public class EntityGraphMapper {
}
if (CollectionUtils.isNotEmpty(newElements)) {
+ if (cardinality == SET) {
+ newElements = (List) newElements.stream().distinct().collect(Collectors.toList());
+ }
+
for (int index = 0; index < newElements.size(); index++) {
AtlasEdge existingEdge = getEdgeAt(currentElements, index, elementType);
AttributeMutationContext arrCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), ctx.getAttribute(), newElements.get(index),
@@ -1507,4 +1514,4 @@ public class EntityGraphMapper {
return currentEntityId;
}
-}
\ No newline at end of file
+}