Skip to content

Commit f1c449c

Browse files
committed
feat(listSecurableObjects): add batch retrieval for SCHEMA
1 parent 9031bc9 commit f1c449c

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,44 @@ public static Map<Long, String> getCatalogObjectFullNames(List<Long> ids) {
508508
return catalogIdAndNameMap;
509509
}
510510

511+
public static Map<Long, String> getSchemaObjectFullNames(List<Long> ids) {
512+
List<SchemaPO> schemaPOs =
513+
SessionUtils.getWithoutCommit(
514+
SchemaMetaMapper.class, mapper -> mapper.listSchemaPOsBySchemaIds(ids));
515+
516+
if (schemaPOs == null || schemaPOs.isEmpty()) {
517+
return new HashMap<>();
518+
}
519+
520+
List<Long> catalogIds =
521+
schemaPOs.stream().map(SchemaPO::getCatalogId).collect(Collectors.toList());
522+
523+
Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
524+
525+
HashMap<Long, String> schemaIdAndNameMap = new HashMap<>();
526+
527+
schemaPOs.forEach(
528+
schemaPO -> {
529+
if (schemaPO.getSchemaId() == null) {
530+
schemaIdAndNameMap.put(schemaPO.getSchemaId(), null);
531+
return;
532+
}
533+
534+
String catalogName = catalogIdAndNameMap.getOrDefault(schemaPO.getCatalogId(), null);
535+
if (catalogName == null) {
536+
LOG.warn("The catalog of schema {} may be deleted", schemaPO.getSchemaId());
537+
schemaIdAndNameMap.put(schemaPO.getSchemaId(), null);
538+
return;
539+
}
540+
541+
String fullName = DOT_JOINER.join(catalogName, schemaPO.getSchemaName());
542+
543+
schemaIdAndNameMap.put(schemaPO.getSchemaId(), fullName);
544+
});
545+
546+
return schemaIdAndNameMap;
547+
}
548+
511549
public static Map<Long, String> getCatalogIdAndNameMap(List<Long> catalogIds) {
512550
List<CatalogPO> catalogPOs =
513551
SessionUtils.getWithoutCommit(

core/src/main/java/org/apache/gravitino/storage/relational/service/RoleMetaService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,12 @@ private static List<SecurableObject> listSecurableObjects(RolePO po) {
372372
MetadataObjectService::getMetalakeObjectFullNames,
373373
MetadataObject.Type.CATALOG,
374374
MetadataObjectService::getCatalogObjectFullNames,
375-
MetadataObject.Type.FILESET,
376-
MetadataObjectService::getFilesetObjectFullNames,
375+
MetadataObject.Type.SCHEMA,
376+
MetadataObjectService::getSchemaObjectFullNames,
377377
MetadataObject.Type.TABLE,
378378
MetadataObjectService::getTableObjectFullNames,
379+
MetadataObject.Type.FILESET,
380+
MetadataObjectService::getFilesetObjectFullNames,
379381
MetadataObject.Type.MODEL,
380382
MetadataObjectService::getModelObjectFullNames,
381383
MetadataObject.Type.TOPIC,

0 commit comments

Comments
 (0)