Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIN-1079 : improve code for impact report #3424

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void traverseEdgesUsingBFS(String baseGuid, AtlasLineageListContext line

if(lineageListContext.getImmediateNeighbours()){
// update parents for each entity
updateParentNodesForEachEntity(lineageListContext, ret, lineageParentsForEntityMap, lineageChildrenForEntityMap);
updateNeighbourNodesForEachEntity(lineageListContext, ret, lineageParentsForEntityMap, lineageChildrenForEntityMap);
}

if (currentDepth > lineageListContext.getDepth())
Expand All @@ -540,7 +540,6 @@ private void enqueueNeighbours(AtlasVertex currentVertex, boolean isDataset,
edges = currentVertex.getEdges(OUT, isInputDirection(lineageListContext) ? PROCESS_INPUTS_EDGE : PROCESS_OUTPUTS_EDGE).iterator();
RequestContext.get().endMetricRecord(traverseEdgesOnDemandGetEdges);

List<String> neighbors = new ArrayList<>();
while (edges.hasNext()) {
AtlasEdge currentEdge = edges.next();
if (!lineageListContext.evaluateTraversalFilter(currentEdge))
Expand Down Expand Up @@ -572,82 +571,56 @@ private void enqueueNeighbours(AtlasVertex currentVertex, boolean isDataset,
}
}

private void updateParentNodesForEachEntity(AtlasLineageListContext lineageListContext, AtlasLineageListInfo ret, Map<String, List<String>> lineageParentsForEntityMap, Map<String, List<String>> lineageChildrenForEntityMap){
private void updateNeighbourNodesForEachEntity(AtlasLineageListContext lineageListContext, AtlasLineageListInfo ret,
Map<String, List<String>> lineageParentsForEntityMap,
Map<String, List<String>> lineageChildrenForEntityMap) {
AtlasPerfMetrics.MetricRecorder metric = RequestContext.get().startMetricRecord("updateNeighbourNodesForEachEntity");
List<AtlasEntityHeader> entityList = ret.getEntities();
if (entityList != null){
for (AtlasEntityHeader entity : entityList) {
if (entity != null && entity.getGuid() != null) {
// Check if the entity GUID exists in the lineageParentsForEntityMap
if (lineageParentsForEntityMap.containsKey(entity.getGuid())) {
// Get the list of AtlasVertex from the map
List<String> parentNodes = lineageParentsForEntityMap.get(entity.getGuid());
if (parentNodes != null) {
Set<String> seenGuids = new HashSet<>();
List<Map<String,String>> parentNodesOfParentWithDetails = new ArrayList<>();
for (String parentNode : parentNodes) {
if(lineageParentsForEntityMap.containsKey(parentNode)){
List<String> parentsOfParentNodes = lineageParentsForEntityMap.get(parentNode);
if (parentsOfParentNodes != null){
for (String parentOfParent : parentsOfParentNodes) {
AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(this.graph, parentOfParent);
if (vertex != null) {
Map<String, String> details = fetchAttributes(vertex, 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
}
}
}
}
}
}
if (entityList == null) return;

if(isInputDirection(lineageListContext)){
entity.setImmediateDownstream(parentNodesOfParentWithDetails);
}
else{
entity.setImmediateUpstream(parentNodesOfParentWithDetails);
}
}
}
for (AtlasEntityHeader entity : entityList) {
if (entity == null || entity.getGuid() == null) continue;

if (lineageChildrenForEntityMap.containsKey(entity.getGuid())) {
// Get the list of AtlasVertex from the map
List<String> childrenNodes = lineageChildrenForEntityMap.get(entity.getGuid());
if (childrenNodes != null) {
Set<String> seenGuids = new HashSet<>();
List<Map<String,String>> childrenNodesOfChildrenWithDetails = new ArrayList<>();
for (String childNode : childrenNodes) {
if(lineageChildrenForEntityMap.containsKey(childNode)){
// Add all children for the current childNode
List<String> childrenOfChildNode = lineageChildrenForEntityMap.get(childNode);
if (childrenOfChildNode != null){
for (String childOfChild : childrenOfChildNode) {
AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(this.graph, childOfChild);
if (vertex != null) {
Map<String, String> details = fetchAttributes(vertex, FETCH_ENTITY_ATTRIBUTES);
if (!seenGuids.contains(childOfChild)) {
childrenNodesOfChildrenWithDetails.add(details);
seenGuids.add(childOfChild); // Add the guid to the set
}
}
}
}
}
}
updateLineageForEntity(entity, lineageParentsForEntityMap, true, lineageListContext);
updateLineageForEntity(entity, lineageChildrenForEntityMap, false, lineageListContext);
}
RequestContext.get().endMetricRecord(metric);
}

if(isInputDirection(lineageListContext)){
entity.setImmediateUpstream(childrenNodesOfChildrenWithDetails);
}
else{
entity.setImmediateDownstream(childrenNodesOfChildrenWithDetails);
}
}
}
private void updateLineageForEntity(AtlasEntityHeader entity, Map<String, List<String>> lineageMap,
boolean isParentMap, AtlasLineageListContext lineageListContext) {
List<String> relatedProcessNodes = lineageMap.get(entity.getGuid());
if (relatedProcessNodes == null) return;

Set<String> seenGuids = new HashSet<>();
List<Map<String, String>> relatedDatasetNodes = new ArrayList<>();

for (String node : relatedProcessNodes) {
List<String> subNodes = lineageMap.get(node);
akshaysw marked this conversation as resolved.
Show resolved Hide resolved
if (subNodes == null) continue;

for (String subNode : subNodes) {
AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(this.graph, subNode);
if (vertex != null && seenGuids.add(subNode)) {
Map<String, String> details = fetchAttributes(vertex, FETCH_ENTITY_ATTRIBUTES);
relatedDatasetNodes.add(details);
}
}
}

if (isParentMap) {
if (isInputDirection(lineageListContext)) {
entity.setImmediateDownstream(relatedDatasetNodes);
} else {
entity.setImmediateUpstream(relatedDatasetNodes);
}
} else {
if (isInputDirection(lineageListContext)) {
entity.setImmediateUpstream(relatedDatasetNodes);
} else {
entity.setImmediateDownstream(relatedDatasetNodes);
}
}
}

private void appendToResult(AtlasVertex currentVertex, AtlasLineageListContext lineageListContext,
Expand Down
Loading