Skip to content

Commit

Permalink
feat(lineage): give via and paths in entity lineage response (#10192)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien authored Apr 3, 2024
1 parent 57de905 commit 888a1de
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.linkedin.datahub.graphql.resolvers.load;

import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*;
import static com.linkedin.datahub.graphql.types.mappers.MapperUtils.*;

import com.datahub.authorization.AuthorizationConfiguration;
import com.linkedin.common.UrnArrayArray;
import com.linkedin.common.urn.Urn;
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.data.template.SetMode;
Expand Down Expand Up @@ -156,6 +158,11 @@ private LineageRelationship mapEntityRelationship(
result.setUpdatedActor(UrnToEntityMapper.map(context, updatedActor));
}
result.setIsManual(lineageRelationship.hasIsManual() && lineageRelationship.isIsManual());
if (lineageRelationship.getPaths() != null) {
UrnArrayArray paths = lineageRelationship.getPaths();
result.setPaths(
paths.stream().map(path -> mapPath(context, path)).collect(Collectors.toList()));
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static com.linkedin.datahub.graphql.util.SearchInsightsUtil.*;
import static com.linkedin.metadata.utils.SearchUtil.*;

import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.AggregationMetadata;
import com.linkedin.datahub.graphql.generated.EntityPath;
import com.linkedin.datahub.graphql.generated.FacetMetadata;
import com.linkedin.datahub.graphql.generated.MatchedField;
import com.linkedin.datahub.graphql.generated.SearchResult;
Expand Down Expand Up @@ -104,4 +106,11 @@ public static SearchSuggestion mapSearchSuggestion(
return new SearchSuggestion(
suggestion.getText(), suggestion.getScore(), Math.toIntExact(suggestion.getFrequency()));
}

public static EntityPath mapPath(@Nullable final QueryContext context, UrnArray path) {
EntityPath entityPath = new EntityPath();
entityPath.setPath(
path.stream().map(p -> UrnToEntityMapper.map(context, p)).collect(Collectors.toList()));
return entityPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import static com.linkedin.datahub.graphql.types.mappers.MapperUtils.*;
import static com.linkedin.datahub.graphql.util.SearchInsightsUtil.*;

import com.linkedin.common.UrnArray;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.generated.EntityPath;
import com.linkedin.datahub.graphql.generated.FreshnessStats;
import com.linkedin.datahub.graphql.generated.SearchAcrossLineageResult;
import com.linkedin.datahub.graphql.generated.SearchAcrossLineageResults;
Expand Down Expand Up @@ -72,13 +70,7 @@ private SearchAcrossLineageResult mapResult(
.setDegree(searchEntity.getDegree())
.setDegrees(new ArrayList<>(searchEntity.getDegrees()))
.setExplored(Boolean.TRUE.equals(searchEntity.isExplored()))
.setIgnoredAsHop(Boolean.TRUE.equals(searchEntity.isIgnoredAsHop()))
.build();
}

private EntityPath mapPath(@Nullable final QueryContext context, UrnArray path) {
EntityPath entityPath = new EntityPath();
entityPath.setPath(
path.stream().map(p -> UrnToEntityMapper.map(context, p)).collect(Collectors.toList()));
return entityPath;
}
}
4 changes: 4 additions & 0 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,10 @@ type LineageRelationship {
"""
isManual: Boolean

"""
The paths traversed for this relationship
"""
paths: [EntityPath]
}

"""
Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/search.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ type SearchAcrossLineageResult {
"""
explored: Boolean!

"""
Whether this relationship was ignored as a hop
"""
ignoredAsHop: Boolean!

}

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ private Stream<Urn> processOneHopLineage(
|| platformMatches(
lineageRelationship.getEntity(),
ignoreAsHops.get(entityType)))))
.map(LineageRelationship::getEntity)
.forEach(additionalCurrentLevel::add);
;
.forEach(
lineageRelationship -> {
additionalCurrentLevel.add(lineageRelationship.getEntity());
lineageRelationship.setIgnoredAsHop(true);
});
if (!additionalCurrentLevel.isEmpty()) {
Stream<Urn> ignoreAsHopUrns =
processOneHopLineage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ private LineageSearchEntity buildLineageSearchEntity(
entity.setDegrees(lineageRelationship.getDegrees());
}
entity.setExplored(Boolean.TRUE.equals(lineageRelationship.isExplored()));
entity.setIgnoredAsHop(Boolean.TRUE.equals(lineageRelationship.isIgnoredAsHop()));
}
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ record LineageRelationship {
* Marks this relationship as explored during the graph walk
*/
explored: optional boolean

/**
* Whether this relationship was ignored as a hop while performing the graph walk
*/
ignoredAsHop: optional boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ record LineageSearchEntity includes SearchEntity {
* Marks an entity as having been explored for as a part of the graph walk
*/
explored: optional boolean

/**
* Whether this relationship was ignored as a hop while performing the graph walk
*/
ignoredAsHop: optional boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -6210,6 +6210,11 @@
"type" : "boolean",
"doc" : "Marks an entity as having been explored for as a part of the graph walk",
"optional" : true
}, {
"name" : "ignoredAsHop",
"type" : "boolean",
"doc" : "Whether this relationship was ignored as a hop while performing the graph walk",
"optional" : true
} ]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
"type" : "boolean",
"doc" : "Marks this relationship as explored during the graph walk",
"optional" : true
}, {
"name" : "ignoredAsHop",
"type" : "boolean",
"doc" : "Whether this relationship was ignored as a hop while performing the graph walk",
"optional" : true
} ]
}
},
Expand Down

0 comments on commit 888a1de

Please sign in to comment.