yuqi1129 commented on code in PR #5075:
URL: https://github.com/apache/gravitino/pull/5075#discussion_r1794970774


##########
core/src/main/java/org/apache/gravitino/utils/MetadataObjectUtil.java:
##########
@@ -98,4 +104,77 @@ public static NameIdentifier toEntityIdent(String 
metalakeName, MetadataObject m
             "Unknown metadata object type: " + metadataObject.type());
     }
   }
+
+  /**
+   * This method will check if the entity is existed explicitly, internally 
this check will load the
+   * entity from underlying sources to entity store if not stored, and will 
allocate an uid for this
+   * entity, with this uid tags can be associated with this entity. This 
method should be called out
+   * of the tree lock, otherwise it will cause deadlock.
+   *
+   * @param metalake The metalake name
+   * @param object The metadata object
+   * @param env The Gravitino environment
+   * @throws NoSuchMetadataObjectException if the metadata object type doesn't 
exist.
+   */
+  public static void checkMetadataObject(String metalake, MetadataObject 
object, GravitinoEnv env) {
+    NameIdentifier identifier = toEntityIdent(metalake, object);
+
+    Supplier<NoSuchMetadataObjectException> exceptionToThrowSupplier =
+        () ->
+            new NoSuchMetadataObjectException(
+                "Metadata object %s type %s doesn't exist", object.fullName(), 
object.type());
+
+    switch (object.type()) {
+      case METALAKE:
+        NameIdentifierUtil.checkMetalake(identifier);
+        check(env.metalakeDispatcher().metalakeExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case CATALOG:
+        NameIdentifierUtil.checkCatalog(identifier);
+        check(env.catalogDispatcher().catalogExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case SCHEMA:
+        NameIdentifierUtil.checkSchema(identifier);
+        check(env.schemaDispatcher().schemaExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case FILESET:
+        NameIdentifierUtil.checkFileset(identifier);
+        check(env.filesetDispatcher().filesetExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case TABLE:
+        NameIdentifierUtil.checkTable(identifier);
+        check(env.tableDispatcher().tableExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case TOPIC:
+        NameIdentifierUtil.checkTopic(identifier);
+        check(env.topicDispatcher().topicExists(identifier), 
exceptionToThrowSupplier);
+        break;
+
+      case ROLE:
+        AuthorizationUtils.checkRole(identifier);
+        try {
+          env.accessControlDispatcher().getRole(metalake, object.fullName());
+        } catch (NoSuchRoleException nsr) {
+          throw checkNotNull(exceptionToThrowSupplier).get();
+        }
+        break;
+
+      case COLUMN:

Review Comment:
   Do we support checking columns or not? If the answer is 'No', you can remove 
`case COLUMN:` here.   



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