tengqm commented on code in PR #5793:
URL: https://github.com/apache/gravitino/pull/5793#discussion_r1875220138


##########
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java:
##########
@@ -162,39 +162,59 @@ private void handleMetalakeCommand() {
 
     Command.setAuthenticationMode(auth, userName);
 
-    if (CommandActions.DETAILS.equals(command)) {
-      if (line.hasOption(GravitinoOptions.AUDIT)) {
-        newMetalakeAudit(url, ignore, metalake).handle();
-      } else {
-        newMetalakeDetails(url, ignore, outputFormat, metalake).handle();
-      }
-    } else if (CommandActions.LIST.equals(command)) {
-      newListMetalakes(url, ignore, outputFormat).handle();
-    } else if (CommandActions.CREATE.equals(command)) {
-      String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-      newCreateMetalake(url, ignore, metalake, comment).handle();
-    } else if (CommandActions.DELETE.equals(command)) {
-      boolean force = line.hasOption(GravitinoOptions.FORCE);
-      newDeleteMetalake(url, ignore, force, metalake).handle();
-    } else if (CommandActions.SET.equals(command)) {
-      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
-      String value = line.getOptionValue(GravitinoOptions.VALUE);
-      newSetMetalakeProperty(url, ignore, metalake, property, value).handle();
-    } else if (CommandActions.REMOVE.equals(command)) {
-      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
-      newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
-    } else if (CommandActions.PROPERTIES.equals(command)) {
-      newListMetalakeProperties(url, ignore, metalake).handle();
-    } else if (CommandActions.UPDATE.equals(command)) {
-      if (line.hasOption(GravitinoOptions.COMMENT)) {
+    switch (command) {
+      case CommandActions.DETAILS:
+        if (line.hasOption(GravitinoOptions.AUDIT)) {
+          newMetalakeAudit(url, ignore, metalake).handle();
+        } else {
+          newMetalakeDetails(url, ignore, outputFormat, metalake).handle();
+        }
+        break;
+
+      case CommandActions.LIST:
+        newListMetalakes(url, ignore, outputFormat).handle();
+        break;
+
+      case CommandActions.CREATE:
         String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-        newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
-      }
-      if (line.hasOption(GravitinoOptions.RENAME)) {
-        String newName = line.getOptionValue(GravitinoOptions.RENAME);
+        newCreateMetalake(url, ignore, metalake, comment).handle();
+        break;
+
+      case CommandActions.DELETE:
         boolean force = line.hasOption(GravitinoOptions.FORCE);
-        newUpdateMetalakeName(url, ignore, force, metalake, newName).handle();
-      }
+        newDeleteMetalake(url, ignore, force, metalake).handle();
+        break;
+
+      case CommandActions.SET:
+        String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+        String value = line.getOptionValue(GravitinoOptions.VALUE);
+        newSetMetalakeProperty(url, ignore, metalake, property, 
value).handle();
+        break;
+
+      case CommandActions.REMOVE:
+        property = line.getOptionValue(GravitinoOptions.PROPERTY);
+        newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
+        break;
+
+      case CommandActions.PROPERTIES:
+        newListMetalakeProperties(url, ignore, metalake).handle();
+        break;
+
+      case CommandActions.UPDATE:
+        if (line.hasOption(GravitinoOptions.COMMENT)) {
+          comment = line.getOptionValue(GravitinoOptions.COMMENT);
+          newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
+        }
+        if (line.hasOption(GravitinoOptions.RENAME)) {
+          String newName = line.getOptionValue(GravitinoOptions.RENAME);
+          force = line.hasOption(GravitinoOptions.FORCE);
+          newUpdateMetalakeName(url, ignore, force, metalake, 
newName).handle();
+        }
+        break;
+
+      default:
+        System.err.println(ErrorMessages.UNSUPPORTED_COMMAND);
+        break;

Review Comment:
   I like this revision. It makes the code much more readable and it also helps 
improve efficiency.



##########
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java:
##########
@@ -652,21 +799,29 @@ private void handleOwnerCommand() {
 
     Command.setAuthenticationMode(auth, userName);
 
-    if (CommandActions.DETAILS.equals(command)) {
-      newOwnerDetails(url, ignore, metalake, entityName, entity).handle();
-    } else if (CommandActions.SET.equals(command)) {
-      String owner = line.getOptionValue(GravitinoOptions.USER);
-      String group = line.getOptionValue(GravitinoOptions.GROUP);
-
-      if (owner != null && group == null) {
-        newSetOwner(url, ignore, metalake, entityName, entity, owner, 
false).handle();
-      } else if (owner == null && group != null) {
-        newSetOwner(url, ignore, metalake, entityName, entity, group, 
true).handle();
-      } else {
-        System.err.println(ErrorMessages.INVALID_SET_COMMAND);
-      }
-    } else {
-      System.err.println(ErrorMessages.UNSUPPORTED_ACTION);
+    switch (command) {
+      case CommandActions.DETAILS:
+        newOwnerDetails(url, ignore, metalake, entityName, entity).handle();
+        break;
+
+      case CommandActions.SET:
+        {
+          String owner = line.getOptionValue(GravitinoOptions.USER);
+          String group = line.getOptionValue(GravitinoOptions.GROUP);
+
+          if (owner != null && group == null) {
+            newSetOwner(url, ignore, metalake, entityName, entity, owner, 
false).handle();
+          } else if (owner == null && group != null) {
+            newSetOwner(url, ignore, metalake, entityName, entity, group, 
true).handle();
+          } else {
+            System.err.println(ErrorMessages.INVALID_SET_COMMAND);
+          }
+          break;
+        }

Review Comment:
   line 808 and 820 can be removed.



##########
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java:
##########
@@ -162,39 +162,59 @@ private void handleMetalakeCommand() {
 
     Command.setAuthenticationMode(auth, userName);
 
-    if (CommandActions.DETAILS.equals(command)) {
-      if (line.hasOption(GravitinoOptions.AUDIT)) {
-        newMetalakeAudit(url, ignore, metalake).handle();
-      } else {
-        newMetalakeDetails(url, ignore, outputFormat, metalake).handle();
-      }
-    } else if (CommandActions.LIST.equals(command)) {
-      newListMetalakes(url, ignore, outputFormat).handle();
-    } else if (CommandActions.CREATE.equals(command)) {
-      String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-      newCreateMetalake(url, ignore, metalake, comment).handle();
-    } else if (CommandActions.DELETE.equals(command)) {
-      boolean force = line.hasOption(GravitinoOptions.FORCE);
-      newDeleteMetalake(url, ignore, force, metalake).handle();
-    } else if (CommandActions.SET.equals(command)) {
-      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
-      String value = line.getOptionValue(GravitinoOptions.VALUE);
-      newSetMetalakeProperty(url, ignore, metalake, property, value).handle();
-    } else if (CommandActions.REMOVE.equals(command)) {
-      String property = line.getOptionValue(GravitinoOptions.PROPERTY);
-      newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
-    } else if (CommandActions.PROPERTIES.equals(command)) {
-      newListMetalakeProperties(url, ignore, metalake).handle();
-    } else if (CommandActions.UPDATE.equals(command)) {
-      if (line.hasOption(GravitinoOptions.COMMENT)) {
+    switch (command) {
+      case CommandActions.DETAILS:
+        if (line.hasOption(GravitinoOptions.AUDIT)) {
+          newMetalakeAudit(url, ignore, metalake).handle();
+        } else {
+          newMetalakeDetails(url, ignore, outputFormat, metalake).handle();
+        }
+        break;
+
+      case CommandActions.LIST:
+        newListMetalakes(url, ignore, outputFormat).handle();
+        break;
+
+      case CommandActions.CREATE:
         String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-        newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
-      }
-      if (line.hasOption(GravitinoOptions.RENAME)) {
-        String newName = line.getOptionValue(GravitinoOptions.RENAME);
+        newCreateMetalake(url, ignore, metalake, comment).handle();
+        break;
+
+      case CommandActions.DELETE:
         boolean force = line.hasOption(GravitinoOptions.FORCE);
-        newUpdateMetalakeName(url, ignore, force, metalake, newName).handle();
-      }
+        newDeleteMetalake(url, ignore, force, metalake).handle();
+        break;
+
+      case CommandActions.SET:
+        String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+        String value = line.getOptionValue(GravitinoOptions.VALUE);
+        newSetMetalakeProperty(url, ignore, metalake, property, 
value).handle();
+        break;
+
+      case CommandActions.REMOVE:
+        property = line.getOptionValue(GravitinoOptions.PROPERTY);
+        newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
+        break;
+
+      case CommandActions.PROPERTIES:
+        newListMetalakeProperties(url, ignore, metalake).handle();
+        break;
+
+      case CommandActions.UPDATE:
+        if (line.hasOption(GravitinoOptions.COMMENT)) {
+          comment = line.getOptionValue(GravitinoOptions.COMMENT);
+          newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
+        }
+        if (line.hasOption(GravitinoOptions.RENAME)) {
+          String newName = line.getOptionValue(GravitinoOptions.RENAME);
+          force = line.hasOption(GravitinoOptions.FORCE);
+          newUpdateMetalakeName(url, ignore, force, metalake, 
newName).handle();
+        }
+        break;
+
+      default:
+        System.err.println(ErrorMessages.UNSUPPORTED_COMMAND);
+        break;

Review Comment:
   A further optimization could be sorting the case values in alphabeta order.



##########
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java:
##########
@@ -538,87 +679,93 @@ private void handleColumnCommand() {
 
     Command.setAuthenticationMode(auth, userName);
 
-    if (CommandActions.LIST.equals(command)) {
-      newListColumns(url, ignore, metalake, catalog, schema, table).handle();
-    } else if (CommandActions.CREATE.equals(command)) {
-      String datatype = line.getOptionValue(GravitinoOptions.DATATYPE);
-      String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-      String position = line.getOptionValue(GravitinoOptions.POSITION);
-      boolean nullable = true;
-      boolean autoIncrement = false;
-      String defaultValue = line.getOptionValue(GravitinoOptions.DEFAULT);
-
-      if (line.hasOption(GravitinoOptions.NULL)) {
-        nullable = line.getOptionValue(GravitinoOptions.NULL).equals("true");
-      }
-
-      if (line.hasOption(GravitinoOptions.AUTO)) {
-        autoIncrement = 
line.getOptionValue(GravitinoOptions.AUTO).equals("true");
-      }
-
-      newAddColumn(
-              url,
-              ignore,
-              metalake,
-              catalog,
-              schema,
-              table,
-              column,
-              datatype,
-              comment,
-              position,
-              nullable,
-              autoIncrement,
-              defaultValue)
-          .handle();
-    } else if (CommandActions.DELETE.equals(command)) {
-      newDeleteColumn(url, ignore, metalake, catalog, schema, table, 
column).handle();
-    } else if (CommandActions.UPDATE.equals(command)) {
-      if (line.hasOption(GravitinoOptions.COMMENT)) {
-        String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-        newUpdateColumnComment(url, ignore, metalake, catalog, schema, table, 
column, comment)
-            .handle();
-      }
-      if (line.hasOption(GravitinoOptions.RENAME)) {
-        String newName = line.getOptionValue(GravitinoOptions.RENAME);
-        newUpdateColumnName(url, ignore, metalake, catalog, schema, table, 
column, newName)
-            .handle();
-      }
-      if (line.hasOption(GravitinoOptions.DATATYPE)) {
-        String datatype = line.getOptionValue(GravitinoOptions.DATATYPE);
-        newUpdateColumnDatatype(url, ignore, metalake, catalog, schema, table, 
column, datatype)
-            .handle();
-      }
-      if (line.hasOption(GravitinoOptions.POSITION)) {
-        String position = line.getOptionValue(GravitinoOptions.POSITION);
-        newUpdateColumnPosition(url, ignore, metalake, catalog, schema, table, 
column, position)
-            .handle();
-      }
-      if (line.hasOption(GravitinoOptions.NULL)) {
-        if (line.getOptionValue(GravitinoOptions.NULL).equals("true")) {
-          newUpdateColumnNullability(url, ignore, metalake, catalog, schema, 
table, column, true)
-              .handle();
-        } else if (line.getOptionValue(GravitinoOptions.NULL).equals("false")) 
{
-          newUpdateColumnNullability(url, ignore, metalake, catalog, schema, 
table, column, false)
+    switch (command) {
+      case CommandActions.LIST:
+        newListColumns(url, ignore, metalake, catalog, schema, table).handle();
+        break;
+
+      case CommandActions.CREATE:
+        {
+          String datatype = line.getOptionValue(GravitinoOptions.DATATYPE);
+          String comment = line.getOptionValue(GravitinoOptions.COMMENT);
+          String position = line.getOptionValue(GravitinoOptions.POSITION);
+          boolean nullable =
+              !line.hasOption(GravitinoOptions.NULL)
+                  || line.getOptionValue(GravitinoOptions.NULL).equals("true");
+          boolean autoIncrement =
+              line.hasOption(GravitinoOptions.AUTO)
+                  && line.getOptionValue(GravitinoOptions.AUTO).equals("true");
+          String defaultValue = line.getOptionValue(GravitinoOptions.DEFAULT);
+
+          newAddColumn(
+                  url,
+                  ignore,
+                  metalake,
+                  catalog,
+                  schema,
+                  table,
+                  column,
+                  datatype,
+                  comment,
+                  position,
+                  nullable,
+                  autoIncrement,
+                  defaultValue)
               .handle();
+          break;
         }
-      }
-      if (line.hasOption(GravitinoOptions.AUTO)) {
-        if (line.getOptionValue(GravitinoOptions.AUTO).equals("true")) {
-          newUpdateColumnAutoIncrement(url, ignore, metalake, catalog, schema, 
table, column, true)
-              .handle();
-        } else if (line.getOptionValue(GravitinoOptions.AUTO).equals("false")) 
{
-          newUpdateColumnAutoIncrement(url, ignore, metalake, catalog, schema, 
table, column, false)
-              .handle();
+
+      case CommandActions.DELETE:
+        newDeleteColumn(url, ignore, metalake, catalog, schema, table, 
column).handle();
+        break;
+
+      case CommandActions.UPDATE:
+        {

Review Comment:
   line 723 and 764 can be safely dropped.



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