-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Impact Analysis): Support impact analysis to check all downstrea…
…ms of given entity (#4322)
- Loading branch information
Dexter Lee
authored
Mar 5, 2022
1 parent
b48b215
commit 18dd5b6
Showing
143 changed files
with
4,452 additions
and
2,042 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rc/main/java/com/linkedin/datahub/graphql/resolvers/load/EntityLineageResultResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.linkedin.datahub.graphql.resolvers.load; | ||
|
||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.Entity; | ||
import com.linkedin.datahub.graphql.generated.EntityLineageResult; | ||
import com.linkedin.datahub.graphql.generated.LineageDirection; | ||
import com.linkedin.datahub.graphql.generated.LineageInput; | ||
import com.linkedin.datahub.graphql.generated.LineageRelationship; | ||
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper; | ||
import com.linkedin.metadata.graph.GraphClient; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
|
||
|
||
/** | ||
* GraphQL Resolver responsible for fetching lineage relationships between entities in the DataHub graph. | ||
* Lineage relationship denotes whether an entity is directly upstream or downstream of another entity | ||
*/ | ||
public class EntityLineageResultResolver implements DataFetcher<CompletableFuture<EntityLineageResult>> { | ||
|
||
private final GraphClient _graphClient; | ||
|
||
public EntityLineageResultResolver(final GraphClient graphClient) { | ||
_graphClient = graphClient; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<EntityLineageResult> get(DataFetchingEnvironment environment) { | ||
final QueryContext context = environment.getContext(); | ||
final String urn = ((Entity) environment.getSource()).getUrn(); | ||
final LineageInput input = bindArgument(environment.getArgument("input"), LineageInput.class); | ||
|
||
final LineageDirection lineageDirection = input.getDirection(); | ||
@Nullable | ||
final Integer start = input.getStart(); // Optional! | ||
@Nullable | ||
final Integer count = input.getCount(); // Optional! | ||
|
||
com.linkedin.metadata.graph.LineageDirection resolvedDirection = | ||
com.linkedin.metadata.graph.LineageDirection.valueOf(lineageDirection.toString()); | ||
return CompletableFuture.supplyAsync(() -> mapEntityRelationships(lineageDirection, | ||
_graphClient.getLineageEntities(urn, resolvedDirection, start, count, 1, context.getActorUrn()))); | ||
} | ||
|
||
private EntityLineageResult mapEntityRelationships(final LineageDirection lineageDirection, | ||
final com.linkedin.metadata.graph.EntityLineageResult entityLineageResult) { | ||
final EntityLineageResult result = new EntityLineageResult(); | ||
result.setStart(entityLineageResult.getStart()); | ||
result.setCount(entityLineageResult.getCount()); | ||
result.setTotal(entityLineageResult.getTotal()); | ||
result.setRelationships(entityLineageResult.getRelationships() | ||
.stream() | ||
.map(entityRelationship -> mapEntityRelationship(lineageDirection, entityRelationship)) | ||
.collect(Collectors.toList())); | ||
return result; | ||
} | ||
|
||
private LineageRelationship mapEntityRelationship(final LineageDirection direction, | ||
final com.linkedin.metadata.graph.LineageRelationship lineageRelationship) { | ||
final LineageRelationship result = new LineageRelationship(); | ||
final Entity partialEntity = UrnToEntityMapper.map(lineageRelationship.getEntity()); | ||
if (partialEntity != null) { | ||
result.setEntity(partialEntity); | ||
} | ||
result.setType(lineageRelationship.getType()); | ||
result.setDegree(lineageRelationship.getDegree()); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.