diff --git a/metadata-io/metadata-io-api/src/main/java/com/linkedin/metadata/entity/ebean/batch/ChangeItemImpl.java b/metadata-io/metadata-io-api/src/main/java/com/linkedin/metadata/entity/ebean/batch/ChangeItemImpl.java index 2f3bce6e75e14..30e9251982f10 100644 --- a/metadata-io/metadata-io-api/src/main/java/com/linkedin/metadata/entity/ebean/batch/ChangeItemImpl.java +++ b/metadata-io/metadata-io-api/src/main/java/com/linkedin/metadata/entity/ebean/batch/ChangeItemImpl.java @@ -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 { diff --git a/metadata-io/src/test/java/com/linkedin/metadata/entity/EntityServiceTest.java b/metadata-io/src/test/java/com/linkedin/metadata/entity/EntityServiceTest.java index feacc24423edb..2a9a8a50b6fe0 100644 --- a/metadata-io/src/test/java/com/linkedin/metadata/entity/EntityServiceTest.java +++ b/metadata-io/src/test/java/com/linkedin/metadata/entity/EntityServiceTest.java @@ -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; @@ -533,6 +534,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()); @@ -595,6 +601,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()); @@ -606,6 +617,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 latestAspects = _entityServiceImpl.getLatestAspectsForUrn(