You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "khmgobe (via GitHub)" <gi...@apache.org> on 2024/08/01 07:25:30 UTC

[PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

khmgobe opened a new pull request, #4335:
URL: https://github.com/apache/gravitino/pull/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


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "khmgobe (via GitHub)" <gi...@apache.org>.
khmgobe commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700077996


##########
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 > 0) {

Review Comment:
   @xloya 
   
   Thank you for your suggestion. I guess I missed something.
   
   ```
   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));
   }
   ```
   
   Is it correct that you mentioned changing it like this? If it is, we will proceed with the change like this.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "khmgobe (via GitHub)" <gi...@apache.org>.
khmgobe commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700274961


##########
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 > 0) {

Review Comment:
   @xloya 
   I think we'd better change the code if multiple people's opinions are set in one direction! Good evening.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#issuecomment-2262867253

   @xloya would you please help to review this code?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "xloya (via GitHub)" <gi...@apache.org>.
xloya commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700071663


##########
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 > 0) {

Review Comment:
   How about using `namespace.levels().length >=1` here? The same treatment is also applied below.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "khmgobe (via GitHub)" <gi...@apache.org>.
khmgobe commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1703565094


##########
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 > 0) {

Review Comment:
   @jerryshao I revised the code as per the common opinion, so please check it.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "xloya (via GitHub)" <gi...@apache.org>.
xloya commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700199535


##########
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 > 0) {

Review Comment:
   @justinmclean Hi, according to the current storage structure design, if the namespace has 3 levels, it is reasonable to recursively obtain the parentEntityId 3 times, because we cannot guarantee that the parent resource can be obtained uniquely through Name, so we need to use parentEntityId and Name to locate the upper-level resource at the same time.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1703461421


##########
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 > 0) {

Review Comment:
   Yes, please go ahead.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "khmgobe (via GitHub)" <gi...@apache.org>.
khmgobe commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1702505708


##########
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 > 0) {

Review Comment:
   @jerryshao @justinmclean 
   
   Is there a consensus? 
   Please let me know if you don't.
   
   If it's matched, we're going to make a change.
   
   The reason for asking again is that I think I'll change it
   when it's decided for sure because I'm afraid there will be a change in the future.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "xloya (via GitHub)" <gi...@apache.org>.
xloya commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700202897


##########
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 > 0) {

Review Comment:
   > @xloya
   > 
   > Thank you for your suggestion. I guess I missed something.
   > 
   > ```
   > 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));
   > }
   > ```
   > 
   > Is it correct that you mentioned changing it like this? If it is, we will proceed with the change like this.
   
   Yes, I think this can better express the Namespace levels:
   ```
   if (namespace.levels().length >= 1) {
         ......
   }
   
   if (namespace.levels().length >= 2) {
         ......
   }
   
   if (namespace.levels().length == 3) {
         ......
   }
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1700148822


##########
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 > 0) {

Review Comment:
   parentEntityId only needs to be set once, if the level is 3 it will be set 3 times above.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "xloya (via GitHub)" <gi...@apache.org>.
xloya commented on PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#issuecomment-2262943312

   This change is generally okay for me, except for one minor suggestion.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #4335:
URL: https://github.com/apache/gravitino/pull/4335


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1701128254


##########
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 > 0) {

Review Comment:
   For example if level is 3 then parentEntityId will be set three times with 2 of those values being thrown away. In this order:
   1. via getMetalakeIdByName (result overwritten by 2 and 3)
   2. via getCatalogIdByMetalakeIdAndName  (result overwritten by 3)
   3. via getSchemaIdByCatalogIdAndName
   
   Why not just obtain it by directly calling getSchemaIdByCatalogIdAndName?
   
   e.g reverse the order of the if statements and change them to if/else ifs.



##########
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 > 0) {

Review Comment:
   For example if level is 3 then parentEntityId will be set three times with 2 of those values being thrown away. In this order:
   1. via getMetalakeIdByName (result overwritten by 2 and 3)
   2. via getCatalogIdByMetalakeIdAndName  (result overwritten by 3)
   3. via getSchemaIdByCatalogIdAndName
   
   Why not just obtain it by directly calling getSchemaIdByCatalogIdAndName? e.g reverse the order of the if statements and change them to if/else ifs.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1701128254


##########
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 > 0) {

Review Comment:
   For example if level is 3 then parentEntityId will be set three times with 2 of those values being thrown away. In this order:
   1. via getMetalakeIdByName (result overwritten)
   2. via getCatalogIdByMetalakeIdAndName  (result overwritten)
   3. via getSchemaIdByCatalogIdAndName
   
   Why not just obtain it by directly calling getSchemaIdByCatalogIdAndName?
   
   e.g reverse the order of the if statements and change them to if/else ifs.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1701416713


##########
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 > 0) {

Review Comment:
   I think what @khmgobe is reasonable, it is more readable than the original code, we can also improve like what @xloya mentioned.
   
   The only bad thing is that `parentEntityId` is mutable, which is not a good programming practice, but I think it is acceptable as there's no side-effect here.
   
   @khmgobe would you please modify the code like what @xloya suggested?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4303] improvement(core): Improved removed loop code and readability [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #4335:
URL: https://github.com/apache/gravitino/pull/4335#discussion_r1701126204


##########
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 > 0) {

Review Comment:
   I still think there is no need to set parentEntityId more than once here and recursion is certainly not needed. Step though the code where level is 1,2 or 3 and you'll see it is doing work that is not required.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org