roryqi commented on code in PR #11046:
URL: https://github.com/apache/gravitino/pull/11046#discussion_r3223519584


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/GroupMetaService.java:
##########
@@ -109,6 +109,48 @@ public GroupEntity getGroupByIdentifier(NameIdentifier 
identifier) {
     return POConverters.fromGroupPO(groupPO, rolePOs, identifier.namespace());
   }
 
+  @Monitored(
+      metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+      baseMetricName = "batchGetGroupByIdentifier")
+  public List<GroupEntity> batchGetGroupByIdentifier(List<NameIdentifier> 
identifiers) {
+    if (identifiers == null || identifiers.isEmpty()) {
+      return Collections.emptyList();
+    }
+
+    NameIdentifier firstIdent = identifiers.get(0);
+    Namespace namespace = firstIdent.namespace();
+    String metalake = NameIdentifierUtil.getMetalake(firstIdent);
+
+    for (NameIdentifier identifier : identifiers) {
+      AuthorizationUtils.checkGroup(identifier);
+      Preconditions.checkArgument(
+          identifier.namespace().equals(namespace),
+          "All group identifiers must belong to the same namespace, expected 
%s but got %s",
+          namespace,
+          identifier.namespace());
+    }
+
+    long metalakeId =
+        EntityIdService.getEntityId(NameIdentifier.of(metalake), 
Entity.EntityType.METALAKE);
+    List<String> groupNames =
+        
identifiers.stream().map(NameIdentifier::name).collect(Collectors.toList());
+
+    return SessionUtils.doWithCommitAndFetchResult(
+        GroupMetaMapper.class,
+        mapper -> {
+          List<GroupPO> groupPOs =
+              mapper.batchSelectGroupMetaByMetalakeIdAndNames(metalakeId, 
groupNames);
+          return groupPOs.stream()
+              .map(
+                  groupPO -> {
+                    List<RolePO> rolePOs =
+                        
RoleMetaService.getInstance().listRolesByGroupId(groupPO.getGroupId());

Review Comment:
   This operation will cost a lot. Group entity only needs role names and role 
ids. Could we a use a batch operation to get all the group's role ids and role 
names?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to