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


##########
api/src/main/java/org/apache/gravitino/MetadataObjects.java:
##########
@@ -69,30 +98,21 @@ public static MetadataObject of(List<String> names, 
MetadataObject.Type type) {
         "Cannot create a metadata object with the name length which is greater 
than 4");
     Preconditions.checkArgument(type != null, "Cannot create a metadata object 
with no type");
 
-    Preconditions.checkArgument(
-        names.size() != 1
-            || type == MetadataObject.Type.CATALOG
-            || type == MetadataObject.Type.METALAKE
-            || type == MetadataObject.Type.ROLE
-            || type == MetadataObject.Type.TAG
-            || type == MetadataObject.Type.POLICY,
-        "If the length of names is 1, it must be the CATALOG, METALAKE,TAG, or 
ROLE type");
-
-    Preconditions.checkArgument(
-        names.size() != 2 || type == MetadataObject.Type.SCHEMA,
-        "If the length of names is 2, it must be the SCHEMA type");
-
-    Preconditions.checkArgument(
-        names.size() != 3
-            || type == MetadataObject.Type.FILESET
-            || type == MetadataObject.Type.TABLE
-            || type == MetadataObject.Type.TOPIC
-            || type == MetadataObject.Type.MODEL,
-        "If the length of names is 3, it must be FILESET, TABLE, TOPIC or 
MODEL");
-
-    Preconditions.checkArgument(
-        names.size() != 4 || type == MetadataObject.Type.COLUMN,
-        "If the length of names is 4, it must be COLUMN");
+    if (validSingleLevelNameTypes.contains(type)) {
+      Preconditions.checkArgument(
+          names.size() == 1, "If the type is " + type + ", the length of names 
must be 1");
+    } else if (validTwoLevelNameTypes.contains(type)) {
+      Preconditions.checkArgument(
+          names.size() == 2, "If the type is " + type + ", the length of names 
must be 2");
+    } else if (validThreeLevelNameTypes.contains(type)) {
+      Preconditions.checkArgument(
+          names.size() == 3, "If the type is " + type + ", the length of names 
must be 3");
+    } else if (validFourLevelNameTypes.contains(type)) {
+      Preconditions.checkArgument(
+          names.size() == 4, "If the type is COLUMN, the length of names must 
be 4");
+    } else {
+      throw new IllegalArgumentException("Unsupported metadata object type: " 
+ type);
+    }

Review Comment:
   Fixed.



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