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

feat(structuredProps) Add created and lastModified timestamps to structured prop entity #11419

Merged
Show file tree
Hide file tree
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 @@ -1034,6 +1034,7 @@ private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("assertion", getResolver(assertionType))
.dataFetcher("form", getResolver(formType))
.dataFetcher("view", getResolver(dataHubViewType))
.dataFetcher("structuredProperty", getResolver(structuredPropertyType))
.dataFetcher("listPolicies", new ListPoliciesResolver(this.entityClient))
.dataFetcher("getGrantedPrivileges", new GetGrantedPrivilegesResolver())
.dataFetcher("listUsers", new ListUsersResolver(this.entityClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public CompletableFuture<StructuredPropertyEntity> get(final DataFetchingEnviron
builder.setCardinality(
PropertyCardinality.valueOf(input.getCardinality().toString()));
}
builder.setCreated(context.getOperationContext().getAuditStamp());
builder.setLastModified(context.getOperationContext().getAuditStamp());

MetadataChangeProposal mcp = builder.build();
_entityClient.ingestProposal(context.getOperationContext(), mcp, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public CompletableFuture<StructuredPropertyEntity> get(final DataFetchingEnviron
if (input.getNewEntityTypes() != null) {
input.getNewEntityTypes().forEach(builder::addEntityType);
}
builder.setLastModified(context.getOperationContext().getAuditStamp());

MetadataChangeProposal mcp = builder.build();
_entityClient.ingestProposal(context.getOperationContext(), mcp, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import static com.linkedin.datahub.graphql.util.SearchInsightsUtil.*;
import static com.linkedin.metadata.utils.SearchUtil.*;

import com.linkedin.common.AuditStamp;
import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.StringMap;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.AggregationMetadata;
import com.linkedin.datahub.graphql.generated.CorpUser;
import com.linkedin.datahub.graphql.generated.EntityPath;
import com.linkedin.datahub.graphql.generated.ExtraProperty;
import com.linkedin.datahub.graphql.generated.FacetMetadata;
import com.linkedin.datahub.graphql.generated.MatchedField;
import com.linkedin.datahub.graphql.generated.ResolvedAuditStamp;
import com.linkedin.datahub.graphql.generated.SearchResult;
import com.linkedin.datahub.graphql.generated.SearchSuggestion;
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper;
Expand Down Expand Up @@ -132,4 +135,13 @@ public static EntityPath mapPath(@Nullable final QueryContext context, UrnArray
path.stream().map(p -> UrnToEntityMapper.map(context, p)).collect(Collectors.toList()));
return entityPath;
}

public static ResolvedAuditStamp createResolvedAuditStamp(AuditStamp auditStamp) {
final ResolvedAuditStamp resolvedAuditStamp = new ResolvedAuditStamp();
final CorpUser emptyCreatedUser = new CorpUser();
emptyCreatedUser.setUrn(auditStamp.getActor().toString());
resolvedAuditStamp.setActor(emptyCreatedUser);
resolvedAuditStamp.setTime(auditStamp.getTime());
return resolvedAuditStamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.linkedin.datahub.graphql.generated.StructuredPropertyEntity;
import com.linkedin.datahub.graphql.generated.TypeQualifier;
import com.linkedin.datahub.graphql.types.common.mappers.util.MappingHelper;
import com.linkedin.datahub.graphql.types.mappers.MapperUtils;
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspectMap;
Expand Down Expand Up @@ -74,6 +75,13 @@ private void mapStructuredPropertyDefinition(
if (gmsDefinition.hasTypeQualifier()) {
definition.setTypeQualifier(mapTypeQualifier(gmsDefinition.getTypeQualifier()));
}
if (gmsDefinition.getCreated() != null) {
definition.setCreated(MapperUtils.createResolvedAuditStamp(gmsDefinition.getCreated()));
}
if (gmsDefinition.getLastModified() != null) {
definition.setLastModified(
MapperUtils.createResolvedAuditStamp(gmsDefinition.getLastModified()));
}
definition.setEntityTypes(
gmsDefinition.getEntityTypes().stream()
.map(this::createEntityTypeEntity)
Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ type Query {
"""
role(urn: String!): Role

"""
Fetch a Structured Property by primary key (urn)
"""
structuredProperty(urn: String!): StructuredPropertyEntity

"""
Fetch a ERModelRelationship by primary key (urn)
"""
Expand Down
10 changes: 10 additions & 0 deletions datahub-graphql-core/src/main/resources/properties.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ type StructuredPropertyDefinition {
Whether or not this structured property is immutable
"""
immutable: Boolean!

"""
Audit stamp for when this structured property was created
"""
created: ResolvedAuditStamp

"""
Audit stamp for when this structured property was last modified
"""
lastModified: ResolvedAuditStamp
}

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.linkedin.common.AuditStamp;
import com.linkedin.data.template.StringArrayMap;
import com.linkedin.metadata.aspect.patch.PatchOperationType;
import com.linkedin.structured.PropertyCardinality;
Expand All @@ -29,6 +30,10 @@ public class StructuredPropertyDefinitionPatchBuilder
public static final String ENTITY_TYPES_FIELD = "entityTypes";
public static final String DESCRIPTION_FIELD = "description";
public static final String IMMUTABLE_FIELD = "immutable";
private static final String LAST_MODIFIED_KEY = "lastModified";
private static final String CREATED_KEY = "created";
private static final String TIME_KEY = "time";
private static final String ACTOR_KEY = "actor";

// can only be used when creating a new structured property
public StructuredPropertyDefinitionPatchBuilder setQualifiedName(@Nonnull String name) {
Expand Down Expand Up @@ -134,6 +139,30 @@ public StructuredPropertyDefinitionPatchBuilder setImmutable(boolean immutable)
return this;
}

public StructuredPropertyDefinitionPatchBuilder setLastModified(
@Nonnull AuditStamp lastModified) {
ObjectNode lastModifiedValue = instance.objectNode();
lastModifiedValue.put(TIME_KEY, lastModified.getTime());
lastModifiedValue.put(ACTOR_KEY, lastModified.getActor().toString());

pathValues.add(
ImmutableTriple.of(
PatchOperationType.ADD.getValue(), "/" + LAST_MODIFIED_KEY, lastModifiedValue));

return this;
}

public StructuredPropertyDefinitionPatchBuilder setCreated(@Nonnull AuditStamp created) {
ObjectNode createdValue = instance.objectNode();
createdValue.put(TIME_KEY, created.getTime());
createdValue.put(ACTOR_KEY, created.getActor().toString());

pathValues.add(
ImmutableTriple.of(PatchOperationType.ADD.getValue(), "/" + CREATED_KEY, createdValue));

return this;
}

@Override
protected String getAspectName() {
return STRUCTURED_PROPERTY_DEFINITION_ASPECT_NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace com.linkedin.structured

import com.linkedin.common.AuditStamp
import com.linkedin.common.Urn
import com.linkedin.datahub.DataHubSearchConfig

Expand Down Expand Up @@ -86,5 +87,27 @@ record StructuredPropertyDefinition {
* 20240610, 20240611
*/
version: optional string

/**
* Created Audit stamp
*/
@Searchable = {
"/time": {
"fieldName": "createdTime",
"fieldType": "DATETIME"
}
}
created: optional AuditStamp

/**
* Created Audit stamp
*/
@Searchable = {
"/time": {
"fieldName": "lastModified",
"fieldType": "DATETIME"
}
}
lastModified: optional AuditStamp
}

Loading