Skip to content

Commit 550a9de

Browse files
authored
fix(noCode): Improving efficiency of EntityService "listLatestAspects" API (#2711)
1 parent 1efc08d commit 550a9de

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

gms/impl/src/main/java/com/linkedin/metadata/resources/dataplatform/DataPlatforms.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public Task<DataPlatform> get(
9595
@RestMethod.GetAll
9696
public Task<List<DataPlatform>> getAllDataPlatforms(@Nonnull @PagingContextParam(defaultCount = 100) PagingContext pagingContext) {
9797
return Task.value(_entityService.listLatestAspects(
98+
"dataPlatform",
9899
"dataPlatformInfo",
99100
pagingContext.getStart(),
100101
pagingContext.getCount())

metadata-io/src/main/java/com/linkedin/metadata/entity/EntityService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,19 @@ public abstract VersionedAspect getVersionedAspect(
110110
long version);
111111

112112
/**
113-
* Retrieves a list of all persisted aspects with a specific name, sorted by corresponding urn.
113+
* Retrieves a list of all aspects belonging to an entity of a particular type, sorted by urn.
114114
*
115115
* Note that once we drop support for legacy 'getAllDataPlatforms' endpoint,
116116
* we can drop support for this unless otherwise required. Only visible for backwards compatibility.
117117
*
118-
* @param aspectName name of the aspect requested
118+
* @param entityName name of the entity type the aspect belongs to, e.g. 'dataset'
119+
* @param aspectName name of the aspect requested, e.g. 'ownership'
119120
* @param start the starting index of the returned aspects, used in pagination
120121
* @param count the count of the aspects to be returned, used in pagination
121122
* @return a {@link ListResult} of {@link RecordTemplate}s representing the requested aspect.
122123
*/
123124
public abstract ListResult<RecordTemplate> listLatestAspects(
125+
@Nonnull final String entityName,
124126
@Nonnull final String aspectName,
125127
final int start,
126128
int count);

metadata-io/src/main/java/com/linkedin/metadata/entity/ebean/EbeanAspectDao.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,27 @@ public ListResult<String> listAspectMetadata(
396396

397397
@Nonnull
398398
public ListResult<String> listLatestAspectMetadata(
399+
@Nonnull final String entityName,
399400
@Nonnull final String aspectName,
400401
final int start,
401402
final int pageSize) {
402-
return listAspectMetadata(aspectName, LATEST_ASPECT_VERSION, start, pageSize);
403+
return listAspectMetadata(entityName, aspectName, LATEST_ASPECT_VERSION, start, pageSize);
403404
}
404405

405406
@Nonnull
406407
public ListResult<String> listAspectMetadata(
408+
@Nonnull final String entityName,
407409
@Nonnull final String aspectName,
408410
final long version,
409411
final int start,
410412
final int pageSize) {
411413
validateConnection();
412414

415+
final String urnPrefixMatcher = "urn:li:" + entityName + ":%";
413416
final PagedList<EbeanAspectV2> pagedList = _server.find(EbeanAspectV2.class)
414417
.select(EbeanAspectV2.ALL_COLUMNS)
415418
.where()
419+
.like(EbeanAspectV2.URN_COLUMN, urnPrefixMatcher)
416420
.eq(EbeanAspectV2.ASPECT_COLUMN, aspectName)
417421
.eq(EbeanAspectV2.VERSION_COLUMN, version)
418422
.setFirstRow(start)

metadata-io/src/main/java/com/linkedin/metadata/entity/ebean/EbeanEntityService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ public VersionedAspect getVersionedAspect(@Nonnull Urn urn, @Nonnull String aspe
138138
@Override
139139
@Nonnull
140140
public ListResult<RecordTemplate> listLatestAspects(
141+
@Nonnull final String entityName,
141142
@Nonnull final String aspectName,
142143
final int start,
143144
int count) {
144145

145-
final ListResult<String> aspectMetadataList = _entityDao.listLatestAspectMetadata(aspectName, start, count);
146+
final ListResult<String> aspectMetadataList = _entityDao.listLatestAspectMetadata(entityName, aspectName, start, count);
146147

147148
final List<RecordTemplate> aspects = new ArrayList<>();
148149
for (int i = 0; i < aspectMetadataList.getValues().size(); i++) {

metadata-io/src/test/java/com/linkedin/metadata/entity/EbeanEntityServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void testIngestListLatestAspects() throws Exception {
201201
_entityService.ingestAspect(entityUrn3, aspectName, writeAspect3, TEST_AUDIT_STAMP);
202202

203203
// List aspects
204-
ListResult<RecordTemplate> batch1 = _entityService.listLatestAspects(aspectName, 0, 2);
204+
ListResult<RecordTemplate> batch1 = _entityService.listLatestAspects(entityUrn1.getEntityType(), aspectName, 0, 2);
205205

206206
assertEquals(2, batch1.getNextStart());
207207
assertEquals(2, batch1.getPageSize());
@@ -211,7 +211,7 @@ public void testIngestListLatestAspects() throws Exception {
211211
assertTrue(DataTemplateUtil.areEqual(writeAspect1, batch1.getValues().get(0)));
212212
assertTrue(DataTemplateUtil.areEqual(writeAspect2, batch1.getValues().get(1)));
213213

214-
ListResult<RecordTemplate> batch2 = _entityService.listLatestAspects(aspectName, 2, 2);
214+
ListResult<RecordTemplate> batch2 = _entityService.listLatestAspects(entityUrn1.getEntityType(), aspectName, 2, 2);
215215
assertEquals(1, batch2.getValues().size());
216216
assertTrue(DataTemplateUtil.areEqual(writeAspect3, batch2.getValues().get(0)));
217217
}

0 commit comments

Comments
 (0)