This is an automated email from the ASF dual-hosted git repository.

jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 24b305d33 [#4303] improvement(core): Improved removed loop code and 
readability (#4335)
24b305d33 is described below

commit 24b305d33284d4dce04ecf9ae30991753369383b
Author: khmgobe <[email protected]>
AuthorDate: Mon Aug 5 16:44:48 2024 +0900

    [#4303] improvement(core): Improved removed loop code and readability 
(#4335)
    
    **What changes were proposed in this pull request?**
    Reflect changes to improve readability
    
    **Why are the changes needed?**
    Readability and no unnecessary repetition compared to existing code
    
    Fix: https://github.com/apache/gravitino/issues/4303
    
    **Does this PR introduce any user-facing change?**
    No
    
    **How was this patch tested?**
    Check change code and existing code comparison
---
 .../relational/service/CommonMetaService.java      | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git 
a/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
 
b/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
index 9f3c9eb97..f990e94fd 100644
--- 
a/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
+++ 
b/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
@@ -37,22 +37,20 @@ public class CommonMetaService {
         !namespace.isEmpty() && namespace.levels().length <= 3,
         "Namespace should not be empty and length should be less than or equal 
to 3.");
     Long parentEntityId = null;
-    for (int level = 0; level < namespace.levels().length; level++) {
-      String name = namespace.level(level);
-      switch (level) {
-        case 0:
-          parentEntityId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(name);
-          continue;
-        case 1:
-          parentEntityId =
-              CatalogMetaService.getInstance()
-                  .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
-          continue;
-        case 2:
-          parentEntityId =
-              
SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId, 
name);
-          break;
-      }
+    if (namespace.levels().length >= 1) {
+      parentEntityId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(namespace.level(0));
+    }
+
+    if (namespace.levels().length >= 2) {
+      parentEntityId =
+          CatalogMetaService.getInstance()
+              .getCatalogIdByMetalakeIdAndName(parentEntityId, 
namespace.level(1));
+    }
+
+    if (namespace.levels().length >= 3) {
+      parentEntityId =
+          SchemaMetaService.getInstance()
+              .getSchemaIdByCatalogIdAndName(parentEntityId, 
namespace.level(2));
     }
     Preconditions.checkState(
         parentEntityId != null && parentEntityId > 0,

Reply via email to