From 24b305d33284d4dce04ecf9ae30991753369383b Mon Sep 17 00:00:00 2001 From: khmgobe Date: Mon, 5 Aug 2024 16:44:48 +0900 Subject: [PATCH] [#4303] improvement(core): Improved removed loop code and readability (#4335) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **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 9f3c9eb9745..f990e94fdcc 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 Long getParentEntityIdByNamespace(Namespace namespace) { !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,