Skip to content

Commit

Permalink
feat(models,ui): Support query nodes in lineage (#9850)
Browse files Browse the repository at this point in the history
  • Loading branch information
asikowitz authored Feb 15, 2024
1 parent e246073 commit 3795203
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import com.linkedin.datahub.graphql.generated.ParentDomainsResult;
import com.linkedin.datahub.graphql.generated.PolicyMatchCriterionValue;
import com.linkedin.datahub.graphql.generated.QueryEntity;
import com.linkedin.datahub.graphql.generated.QueryProperties;
import com.linkedin.datahub.graphql.generated.QuerySubject;
import com.linkedin.datahub.graphql.generated.QuickFilter;
import com.linkedin.datahub.graphql.generated.RecommendationContent;
Expand Down Expand Up @@ -2583,9 +2584,27 @@ private void configureQueryEntityResolvers(final RuntimeWiring.Builder builder)
builder
.type(
"QueryEntity",
typeWiring ->
typeWiring
.dataFetcher(
"relationships", new EntityRelationshipsResultResolver(graphClient))
.dataFetcher(
"platform",
new LoadableTypeResolver<>(
dataPlatformType,
(env) -> {
final QueryEntity query = env.getSource();
return query.getPlatform() != null
? query.getPlatform().getUrn()
: null;
})))
.type(
"QueryProperties",
typeWiring ->
typeWiring.dataFetcher(
"relationships", new EntityRelationshipsResultResolver(graphClient)))
"origin",
new EntityTypeResolver(
entityTypes, (env) -> ((QueryProperties) env.getSource()).getOrigin())))
.type(
"ListQueriesResult",
typeWiring ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public List<com.linkedin.datahub.graphql.generated.FineGrainedLineage> apply(
.map(FineGrainedLineagesMapper::mapDatasetSchemaField)
.collect(Collectors.toList()));
}
if (fineGrainedLineage.hasQuery()) {
resultEntry.setQuery(fineGrainedLineage.getQuery().toString());
}
if (fineGrainedLineage.hasTransformOperation()) {
resultEntry.setTransformOperation(fineGrainedLineage.getTransformOperation());
}
result.add(resultEntry);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import static com.linkedin.metadata.Constants.*;

import com.linkedin.common.DataPlatformInstance;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.DataMap;
import com.linkedin.data.template.GetMode;
import com.linkedin.datahub.graphql.generated.AuditStamp;
import com.linkedin.datahub.graphql.generated.DataPlatform;
import com.linkedin.datahub.graphql.generated.Dataset;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.generated.QueryEntity;
import com.linkedin.datahub.graphql.generated.QueryLanguage;
import com.linkedin.datahub.graphql.generated.QuerySource;
import com.linkedin.datahub.graphql.generated.QueryStatement;
import com.linkedin.datahub.graphql.generated.QuerySubject;
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper;
import com.linkedin.datahub.graphql.types.common.mappers.util.MappingHelper;
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
import com.linkedin.entity.EntityResponse;
Expand All @@ -22,7 +25,9 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class QueryMapper implements ModelMapper<EntityResponse, QueryEntity> {

public static final QueryMapper INSTANCE = new QueryMapper();
Expand All @@ -41,9 +46,20 @@ public QueryEntity apply(@Nonnull final EntityResponse entityResponse) {
MappingHelper<QueryEntity> mappingHelper = new MappingHelper<>(aspectMap, result);
mappingHelper.mapToResult(QUERY_PROPERTIES_ASPECT_NAME, this::mapQueryProperties);
mappingHelper.mapToResult(QUERY_SUBJECTS_ASPECT_NAME, this::mapQuerySubjects);
mappingHelper.mapToResult(DATA_PLATFORM_INSTANCE_ASPECT_NAME, this::mapPlatform);
return mappingHelper.getResult();
}

private void mapPlatform(@Nonnull QueryEntity query, @Nonnull DataMap dataMap) {
DataPlatformInstance aspect = new DataPlatformInstance(dataMap);
if (aspect.hasPlatform()) {
final DataPlatform platform = new DataPlatform();
platform.setUrn(aspect.getPlatform().toString());
platform.setType(EntityType.DATA_PLATFORM);
query.setPlatform(platform);
}
}

private void mapQueryProperties(@Nonnull QueryEntity query, @Nonnull DataMap dataMap) {
QueryProperties queryProperties = new QueryProperties(dataMap);
com.linkedin.datahub.graphql.generated.QueryProperties res =
Expand All @@ -57,6 +73,9 @@ private void mapQueryProperties(@Nonnull QueryEntity query, @Nonnull DataMap dat
QueryLanguage.valueOf(queryProperties.getStatement().getLanguage().toString())));
res.setName(queryProperties.getName(GetMode.NULL));
res.setDescription(queryProperties.getDescription(GetMode.NULL));
if (queryProperties.hasOrigin() && queryProperties.getOrigin() != null) {
res.setOrigin(UrnToEntityMapper.map(queryProperties.getOrigin()));
}

AuditStamp created = new AuditStamp();
created.setTime(queryProperties.getCreated().getTime());
Expand Down
14 changes: 13 additions & 1 deletion datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ type RoleUser {

type RoleProperties {
"""
Name of the Role in an organisation
Name of the Role in an organisation
"""
name: String!

Expand All @@ -1584,6 +1584,8 @@ type RoleProperties {
type FineGrainedLineage {
upstreams: [SchemaFieldRef!]
downstreams: [SchemaFieldRef!]
query: String
transformOperation: String
}

"""
Expand Down Expand Up @@ -11200,6 +11202,11 @@ type QueryProperties {
An Audit Stamp corresponding to the update of this resource
"""
lastModified: AuditStamp!

"""
The asset that this query originated from, e.g. a View, a dbt Model, etc.
"""
origin: Entity
}

"""
Expand Down Expand Up @@ -11240,6 +11247,11 @@ type QueryEntity implements Entity {
Granular API for querying edges extending from this entity
"""
relationships(input: RelationshipsInput!): EntityRelationshipsResult

"""
Platform from which the Query was detected
"""
platform: DataPlatform
}

"""
Expand Down
4 changes: 3 additions & 1 deletion datahub-web-react/src/graphql/lineage.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ fragment lineageNodeProperties on EntityWithRelationships {
urn
path
}
query
transformOperation
}
}
health {
Expand Down Expand Up @@ -562,4 +564,4 @@ query getSearchAcrossLineageCounts(
...facetFields
}
}
}
}
8 changes: 7 additions & 1 deletion datahub-web-react/src/graphql/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ query getQuery($urn: String!) {
fragment query on QueryEntity {
urn
properties {
description
name
description
source
statement {
value
Expand All @@ -26,6 +26,12 @@ fragment query on QueryEntity {
time
actor
}
origin {
...searchResultFields
}
}
platform {
...platformFields
}
subjects {
dataset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ record QueryProperties {
lastModified: AuditStamp

/**
* The urn of the DataPlatform where the Query was executed.
* The origin of the Query.
* This is the source of the Query (e.g. a View, Stored Procedure, dbt Model, etc.) that the Query was created from.
*/
dataPlatform: optional Urn
origin: optional Urn

}
4 changes: 3 additions & 1 deletion metadata-models/src/main/resources/entity-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ entities:
- queryProperties
- querySubjects
- status
- dataPlatformInstance
- subTypes
- name: dataProduct
category: core
keyAspect: dataProductKey
Expand Down Expand Up @@ -562,4 +564,4 @@ plugins:
- UPSERT
supportedEntityAspectNames:
- entityName: '*'
aspectName: structuredProperties
aspectName: structuredProperties

0 comments on commit 3795203

Please sign in to comment.