jerqi commented on code in PR #6100:
URL: https://github.com/apache/gravitino/pull/6100#discussion_r1904998425


##########
core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java:
##########
@@ -364,4 +376,127 @@ private static void checkCatalogType(
           catalogIdent, catalog.type(), privilege);
     }
   }
+
+  public static List<String> getMetadataObjectLocation(
+      NameIdentifier ident, Entity.EntityType type) {
+    List<String> locations = new ArrayList<>();
+    MetadataObject metadataObject;
+    try {
+      metadataObject = NameIdentifierUtil.toMetadataObject(ident, type);
+    } catch (IllegalArgumentException e) {
+      LOG.warn("Illegal argument exception for metadata object %s type %s", 
ident, type, e);
+      return locations;
+    }
+
+    String metalake =
+        (type == Entity.EntityType.METALAKE ? ident.name() : 
ident.namespace().level(0));
+    try {
+      switch (metadataObject.type()) {
+        case METALAKE:
+          {
+            NameIdentifier[] identifiers =
+                
GravitinoEnv.getInstance().catalogDispatcher().listCatalogs(Namespace.of(metalake));
+            Arrays.stream(identifiers)
+                .collect(Collectors.toList())
+                .forEach(
+                    identifier -> {
+                      Catalog catalogObj =
+                          
GravitinoEnv.getInstance().catalogDispatcher().loadCatalog(identifier);
+                      if (catalogObj.provider().equals("hive")) {
+                        Schema schema =
+                            GravitinoEnv.getInstance()
+                                .schemaDispatcher()
+                                .loadSchema(
+                                    NameIdentifier.of(
+                                        metalake,
+                                        catalogObj.name(),
+                                        "default" /*Hive default schema*/));
+                        if 
(schema.properties().containsKey(HiveConstants.LOCATION)) {
+                          String defaultSchemaLocation =
+                              schema.properties().get(HiveConstants.LOCATION);
+                          if (defaultSchemaLocation != null && 
!defaultSchemaLocation.isEmpty()) {
+                            locations.add(defaultSchemaLocation);
+                          } else {
+                            LOG.warn("Catalog %s location is not found", 
ident);
+                          }
+                        }
+                      }
+                    });
+          }
+          break;
+        case CATALOG:
+          {
+            Catalog catalogObj = 
GravitinoEnv.getInstance().catalogDispatcher().loadCatalog(ident);
+            if (catalogObj.provider().equals("hive")) {

Review Comment:
   The code is duplicate with 405Line. Could you extract a method?



-- 
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