Skip to content

Commit

Permalink
fix(mcp): fix mcp key aspect (datahub-project#10503)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker authored May 15, 2024
1 parent 334f431 commit 14eaa06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,21 @@ public SystemAspect getSystemAspect(@Nullable Long version) {

@Nonnull
public MetadataChangeProposal getMetadataChangeProposal() {
final MetadataChangeProposal mcp = new MetadataChangeProposal();
mcp.setEntityUrn(getUrn());
mcp.setChangeType(getChangeType());
mcp.setEntityType(getEntitySpec().getName());
mcp.setAspectName(getAspectName());
mcp.setAspect(GenericRecordUtils.serializeAspect(getRecordTemplate()));
mcp.setSystemMetadata(getSystemMetadata());
return mcp;
if (metadataChangeProposal != null) {
return metadataChangeProposal;
} else {
final MetadataChangeProposal mcp = new MetadataChangeProposal();
mcp.setEntityUrn(getUrn());
mcp.setChangeType(getChangeType());
mcp.setEntityType(getEntitySpec().getName());
mcp.setAspectName(getAspectName());
mcp.setAspect(GenericRecordUtils.serializeAspect(getRecordTemplate()));
mcp.setSystemMetadata(getSystemMetadata());
mcp.setEntityKeyAspect(
GenericRecordUtils.serializeAspect(
EntityKeyUtils.convertUrnToEntityKey(getUrn(), entitySpec.getKeyAspectSpec())));
return mcp;
}
}

public static class ChangeItemImplBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.linkedin.metadata.service.UpdateIndicesService;
import com.linkedin.metadata.snapshot.CorpUserSnapshot;
import com.linkedin.metadata.snapshot.Snapshot;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.GenericAspect;
import com.linkedin.mxe.MetadataChangeLog;
Expand Down Expand Up @@ -534,6 +535,11 @@ public void testReingestAspectsGetLatestAspects() throws Exception {

initialChangeLog.setAspect(aspect);
initialChangeLog.setSystemMetadata(metadata1);
initialChangeLog.setEntityKeyAspect(
GenericRecordUtils.serializeAspect(
EntityKeyUtils.convertUrnToEntityKey(
entityUrn,
_testEntityRegistry.getEntitySpec(entityUrn.getEntityType()).getKeyAspectSpec())));

final MetadataChangeLog restateChangeLog = new MetadataChangeLog();
restateChangeLog.setEntityType(entityUrn.getEntityType());
Expand Down Expand Up @@ -596,6 +602,11 @@ public void testReingestLineageAspect() throws Exception {

initialChangeLog.setAspect(aspect);
initialChangeLog.setSystemMetadata(metadata1);
initialChangeLog.setEntityKeyAspect(
GenericRecordUtils.serializeAspect(
EntityKeyUtils.convertUrnToEntityKey(
entityUrn,
_testEntityRegistry.getEntitySpec(entityUrn.getEntityType()).getKeyAspectSpec())));

final MetadataChangeLog restateChangeLog = new MetadataChangeLog();
restateChangeLog.setEntityType(entityUrn.getEntityType());
Expand All @@ -607,6 +618,11 @@ public void testReingestLineageAspect() throws Exception {
restateChangeLog.setSystemMetadata(metadata1);
restateChangeLog.setPreviousAspectValue(aspect);
restateChangeLog.setPreviousSystemMetadata(simulatePullFromDB(metadata1, SystemMetadata.class));
restateChangeLog.setEntityKeyAspect(
GenericRecordUtils.serializeAspect(
EntityKeyUtils.convertUrnToEntityKey(
entityUrn,
_testEntityRegistry.getEntitySpec(entityUrn.getEntityType()).getKeyAspectSpec())));

Map<String, RecordTemplate> latestAspects =
_entityServiceImpl.getLatestAspectsForUrn(
Expand Down

0 comments on commit 14eaa06

Please sign in to comment.