Skip to content

Commit e5ce283

Browse files
jsdonnJustin Donn
andauthored
fix(relationship): ignore 'pegasus.' prefix when comparing aspect FQCN (#557)
Co-authored-by: Justin Donn <jdonn@jdonn-mn3766.linkedin.biz>
1 parent 8f17ced commit e5ce283

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalRelationshipWriterDAO.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,15 @@ private <ASPECT extends RecordTemplate> void removeRelationshipsBySource(@Nonnul
218218
SqlUpdate deletionSQL = _server.createSqlUpdate(SQLStatementUtils.deleteLocalRelationshipSQL(tableName, _useAspectColumnForRelationshipRemoval));
219219
deletionSQL.setParameter(CommonColumnName.SOURCE, source.toString());
220220
if (_useAspectColumnForRelationshipRemoval) {
221-
deletionSQL.setParameter(CommonColumnName.ASPECT, aspectClass.getCanonicalName());
221+
// treat "pegasus.com.linkedin..." and "com.linkedin..." as equivalent
222+
String aspectClassFQCN = aspectClass.getCanonicalName();
223+
String pegasusPrefix = "pegasus.";
224+
// normalize the aspect FQCN first by removing any 'pegasus.' prefix
225+
if (aspectClassFQCN.startsWith(pegasusPrefix)) {
226+
aspectClassFQCN = aspectClassFQCN.substring(pegasusPrefix.length());
227+
}
228+
deletionSQL.setParameter(CommonColumnName.ASPECT, aspectClassFQCN); // WHERE aspect = "com.linkedin..."
229+
deletionSQL.setParameter("pegasus_" + CommonColumnName.ASPECT, pegasusPrefix + aspectClassFQCN); // OR aspect = "pegasus.com.linkedin..."
222230
}
223231
batchCount = 0;
224232
while (batchCount < MAX_BATCHES) {

dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/utils/SQLStatementUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public class SQLStatementUtils {
141141
+ "WHERE source = :source AND deleted_ts IS NULL";
142142

143143
private static final String DELETE_BY_SOURCE_AND_ASPECT = "UPDATE %s SET deleted_ts=NOW() "
144-
+ "WHERE source = :source AND aspect = :aspect AND deleted_ts IS NULL";
144+
+ "WHERE source = :source AND (aspect = :aspect OR aspect = :pegasus_aspect) AND deleted_ts IS NULL";
145145

146146
/**
147147
* Filter query has pagination params in the existing APIs. To accommodate this, we use subquery to include total result counts in the query response.

dao-impl/ebean-dao/src/test/java/com/linkedin/metadata/dao/localrelationship/EbeanLocalRelationshipWriterDAOTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,37 @@ public void testRemoveRelationshipsDifferentAspect() throws URISyntaxException {
318318
_server.execute(Ebean.createSqlUpdate("truncate metadata_relationship_pairswith"));
319319
}
320320

321+
@Test
322+
public void testRemoveRelationshipsSameAspectDifferentNamespace() throws URISyntaxException {
323+
if (!_useAspectColumnForRelationshipRemoval) {
324+
return; // this test doesn't apply to this case
325+
}
326+
_localRelationshipWriterDAO.setUseAspectColumnForRelationshipRemoval(_useAspectColumnForRelationshipRemoval);
327+
328+
BarUrn barUrn = BarUrn.createFromString("urn:li:bar:123");
329+
FooUrn fooUrn123 = FooUrn.createFromString("urn:li:foo:123");
330+
FooUrn fooUrn456 = FooUrn.createFromString("urn:li:foo:456");
331+
_server.execute(Ebean.createSqlUpdate(insertRelationships("metadata_relationship_pairswith", barUrn.toString(),
332+
"bar", fooUrn123.toString(), "foo", AspectFooBar.class.getCanonicalName())));
333+
334+
_server.execute(Ebean.createSqlUpdate(insertRelationships("metadata_relationship_pairswith", barUrn.toString(),
335+
"bar", fooUrn456.toString(), "foo", "pegasus." + AspectFooBar.class.getCanonicalName())));
336+
337+
// Before processing
338+
List<SqlRow> before = _server.createSqlQuery("select * from metadata_relationship_pairswith where deleted_ts is null").findList();
339+
assertEquals(before.size(), 2);
340+
341+
PairsWith pairsWith = new PairsWith().setSource(barUrn).setDestination(fooUrn123);
342+
_localRelationshipWriterDAO.removeRelationships(barUrn, AspectFooBar.class, Collections.singletonList(pairsWith));
343+
344+
// After processing verification - both relationships should have been deleted.
345+
List<SqlRow> all = _server.createSqlQuery("select * from metadata_relationship_pairswith where deleted_ts is null").findList();
346+
assertEquals(all.size(), 0); // Total number of edges is 0
347+
348+
// Clean up
349+
_server.execute(Ebean.createSqlUpdate("truncate metadata_relationship_pairswith"));
350+
}
351+
321352
private String insertRelationships(String table, String sourceUrn, String sourceType, String destinationUrn, String destinationType, String aspect) {
322353
String insertWithAspectTemplate = "INSERT INTO %s (metadata, source, source_type, destination, destination_type, lastmodifiedon, lastmodifiedby, aspect)"
323354
+ " VALUES ('{\"metadata\": true}', '%s', '%s', '%s', '%s', CURRENT_TIMESTAMP, 'unknown', '%s')";

0 commit comments

Comments
 (0)