FANNG1 commented on code in PR #6100:
URL: https://github.com/apache/gravitino/pull/6100#discussion_r1905144289
##########
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")) {
+ 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 SCHEMA:
+ {
+ Schema schema =
GravitinoEnv.getInstance().schemaDispatcher().loadSchema(ident);
+ if (schema.properties().containsKey(HiveConstants.LOCATION)) {
+ String schemaLocation =
schema.properties().get(HiveConstants.LOCATION);
+ if (schemaLocation != null && schemaLocation.isEmpty()) {
+ locations.add(schemaLocation);
+ } else {
+ LOG.warn("Schema %s location is not found", ident);
+ }
+ }
+ }
+ break;
+ case TABLE:
+ {
+ Table table =
GravitinoEnv.getInstance().tableDispatcher().loadTable(ident);
Review Comment:
`getInstance().tableDispatcher()` contains too many unnesseary dispatchers,
what you need is `TableOperationDispatcher` YES?
--
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]