Skip to content

Commit

Permalink
feat(listSecurableObjects): add batch retrieval for SCHEMA
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowntpo committed Mar 6, 2025
1 parent 9031bc9 commit f1c449c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,44 @@ public static Map<Long, String> getCatalogObjectFullNames(List<Long> ids) {
return catalogIdAndNameMap;
}

public static Map<Long, String> getSchemaObjectFullNames(List<Long> ids) {
List<SchemaPO> schemaPOs =
SessionUtils.getWithoutCommit(
SchemaMetaMapper.class, mapper -> mapper.listSchemaPOsBySchemaIds(ids));

if (schemaPOs == null || schemaPOs.isEmpty()) {
return new HashMap<>();
}

List<Long> catalogIds =
schemaPOs.stream().map(SchemaPO::getCatalogId).collect(Collectors.toList());

Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);

HashMap<Long, String> schemaIdAndNameMap = new HashMap<>();

schemaPOs.forEach(
schemaPO -> {
if (schemaPO.getSchemaId() == null) {
schemaIdAndNameMap.put(schemaPO.getSchemaId(), null);
return;
}

String catalogName = catalogIdAndNameMap.getOrDefault(schemaPO.getCatalogId(), null);
if (catalogName == null) {
LOG.warn("The catalog of schema {} may be deleted", schemaPO.getSchemaId());
schemaIdAndNameMap.put(schemaPO.getSchemaId(), null);
return;
}

String fullName = DOT_JOINER.join(catalogName, schemaPO.getSchemaName());

schemaIdAndNameMap.put(schemaPO.getSchemaId(), fullName);
});

return schemaIdAndNameMap;
}

public static Map<Long, String> getCatalogIdAndNameMap(List<Long> catalogIds) {
List<CatalogPO> catalogPOs =
SessionUtils.getWithoutCommit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ private static List<SecurableObject> listSecurableObjects(RolePO po) {
MetadataObjectService::getMetalakeObjectFullNames,
MetadataObject.Type.CATALOG,
MetadataObjectService::getCatalogObjectFullNames,
MetadataObject.Type.FILESET,
MetadataObjectService::getFilesetObjectFullNames,
MetadataObject.Type.SCHEMA,
MetadataObjectService::getSchemaObjectFullNames,
MetadataObject.Type.TABLE,
MetadataObjectService::getTableObjectFullNames,
MetadataObject.Type.FILESET,
MetadataObjectService::getFilesetObjectFullNames,
MetadataObject.Type.MODEL,
MetadataObjectService::getModelObjectFullNames,
MetadataObject.Type.TOPIC,
Expand Down

0 comments on commit f1c449c

Please sign in to comment.