From 0aa54361f1a65187bd674eeb9d6405b0a4d24dcf Mon Sep 17 00:00:00 2001 From: akshaysw Date: Thu, 22 Aug 2024 17:46:22 +0530 Subject: [PATCH] [fix] remove duplicate entries --- .../atlas/discovery/EntityLineageService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java index 63563a5b0e..e1640a370c 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java @@ -579,12 +579,17 @@ private void updateParentNodesForEachEntity(AtlasLineageListContext lineageListC if (lineageParentsForEntityMap.containsKey(entity.getGuid())) { // Get the list of AtlasVertex from the map List parentNodes = lineageParentsForEntityMap.get(entity.getGuid()); - + Set seenGuids = new HashSet<>(); List> parentNodesOfParentWithDetails = new ArrayList<>(); for (String parentNode : parentNodes) { List parentsOfParentNodes = lineageParentsForEntityMap.get(parentNode); for (String parentOfParent : parentsOfParentNodes) { - parentNodesOfParentWithDetails.add(fetchAttributes(AtlasGraphUtilsV2.findByGuid(this.graph, parentOfParent), FETCH_ENTITY_ATTRIBUTES)); + Map details = fetchAttributes(AtlasGraphUtilsV2.findByGuid(this.graph, parentOfParent), FETCH_ENTITY_ATTRIBUTES); + // Check if the guid is already in the set + if (!seenGuids.contains(parentOfParent)) { + parentNodesOfParentWithDetails.add(details); + seenGuids.add(parentOfParent); // Add the guid to the set + } } } @@ -599,13 +604,17 @@ private void updateParentNodesForEachEntity(AtlasLineageListContext lineageListC if (lineageChildrenForEntityMap.containsKey(entity.getGuid())) { // Get the list of AtlasVertex from the map List childrenNodes = lineageChildrenForEntityMap.get(entity.getGuid()); - + Set seenGuids = new HashSet<>(); List> childrenNodesOfChildrenWithDetails = new ArrayList<>(); for (String childNode : childrenNodes) { // Add all children for the current childNode List childrenOfChildNode = lineageChildrenForEntityMap.get(childNode); for (String childOfChild : childrenOfChildNode) { - childrenNodesOfChildrenWithDetails.add(fetchAttributes(AtlasGraphUtilsV2.findByGuid(this.graph, childOfChild), FETCH_ENTITY_ATTRIBUTES)); + Map details = fetchAttributes(AtlasGraphUtilsV2.findByGuid(this.graph, childOfChild), FETCH_ENTITY_ATTRIBUTES); + if (!seenGuids.contains(childOfChild)) { + childrenNodesOfChildrenWithDetails.add(details); + seenGuids.add(childOfChild); // Add the guid to the set + } } }