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


##########
core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java:
##########
@@ -364,4 +376,123 @@ 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);
+                          Preconditions.checkArgument(
+                              defaultSchemaLocation != null,
+                              String.format("Catalog %s location is not 
found", ident));
+                          locations.add(defaultSchemaLocation);
+                        }
+                      }
+                    });
+          }
+          break;
+        case CATALOG:
+          {
+            Catalog catalogObj = 
GravitinoEnv.getInstance().catalogDispatcher().loadCatalog(ident);
+            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);
+                Preconditions.checkArgument(
+                    defaultSchemaLocation != null,
+                    String.format("Catalog %s location is not found", ident));
+                locations.add(defaultSchemaLocation);
+              }
+            }
+          }
+          break;
+        case SCHEMA:
+          {
+            Schema schema = 
GravitinoEnv.getInstance().schemaDispatcher().loadSchema(ident);
+            if (schema.properties().containsKey(HiveConstants.LOCATION)) {
+              String schemaLocation = 
schema.properties().get(HiveConstants.LOCATION);
+              Preconditions.checkArgument(
+                  schemaLocation != null, String.format("Schema %s location is 
not found", ident));
+              locations.add(schemaLocation);
+            }
+          }
+          break;
+        case TABLE:
+          {
+            Table table = 
GravitinoEnv.getInstance().tableDispatcher().loadTable(ident);
+            if (table.properties().containsKey(HiveConstants.LOCATION)) {
+              String schemaLocation = 
table.properties().get(HiveConstants.LOCATION);
+              Preconditions.checkArgument(
+                  schemaLocation != null, String.format("Table %s location is 
not found", ident));
+              locations.add(schemaLocation);
+            }
+          }
+          break;
+        case FILESET:
+          FilesetDispatcher filesetDispatcher = 
GravitinoEnv.getInstance().filesetDispatcher();
+          NameIdentifier identifier = getObjectNameIdentifier(metalake, 
metadataObject);
+          Fileset fileset = filesetDispatcher.loadFileset(identifier);
+          Preconditions.checkArgument(
+              fileset != null, String.format("Fileset %s is not found", 
identifier));
+          String filesetLocation = fileset.storageLocation();
+          Preconditions.checkArgument(
+              filesetLocation != null,
+              String.format("Fileset %s location is not found", identifier));
+          locations.add(filesetLocation);
+          break;
+        case TOPIC:

Review Comment:
   Should we remove the `TOPIC` case?



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