You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/12/04 17:07:39 UTC

[GitHub] [incubator-doris] jackwener opened a new pull request #7302: [refactor] modify the control flow code to improve code readability

jackwener opened a new pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302


   ## Proposed changes
   
   Now the code of command handler isn't clear.
   
   We can modify `if` and `else` to improve code readability.
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] Documentation Update (if none of the other choices apply)
   - [x] Code refactor (Modify the code structure, format the code, etc...)
   - [ ] Optimization. Including functional usability improvements and performance improvements.
   - [ ] Dependency. Such as changes related to third-party components.
   - [ ] Other.
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [ ] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
   - [ ] Compiling and unit tests pass locally with my changes
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] If these changes need document changes, I have updated the document
   - [ ] Any dependent changes have been merged
   
   ## Further comments
   
   None
   


-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on a change in pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302#discussion_r765400309



##########
File path: fe/fe-core/src/main/java/org/apache/doris/PaloFe.java
##########
@@ -232,63 +232,67 @@ private static CommandLineOptions parseArgs(String[] args) {
         // version
         if (cmd.hasOption('v') || cmd.hasOption("version")) {
             return new CommandLineOptions(true, "", null);
-        } else if (cmd.hasOption('b') || cmd.hasOption("bdb")) {
+        }
+        // helper
+        if (cmd.hasOption('h') || cmd.hasOption("helper")) {
+            String helperNode = cmd.getOptionValue("helper");
+            if (Strings.isNullOrEmpty(helperNode)) {
+                System.err.println("Missing helper node");
+                System.exit(-1);
+            }
+            return new CommandLineOptions(false, helperNode, null);
+        }
+
+        if (cmd.hasOption('b') || cmd.hasOption("bdb")) {
             if (cmd.hasOption('l') || cmd.hasOption("listdb")) {
                 // list bdb je databases
                 BDBToolOptions bdbOpts = new BDBToolOptions(true, "", false, "", "", 0);
                 return new CommandLineOptions(false, "", bdbOpts);
-            } else if (cmd.hasOption('d') || cmd.hasOption("db")) {
+            } 
+            if (cmd.hasOption('d') || cmd.hasOption("db")) {
                 // specify a database
                 String dbName = cmd.getOptionValue("db");
                 if (Strings.isNullOrEmpty(dbName)) {
                     System.err.println("BDBJE database name is missing");
                     System.exit(-1);
                 }
-
                 if (cmd.hasOption('s') || cmd.hasOption("stat")) {
                     BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, true, "", "", 0);
                     return new CommandLineOptions(false, "", bdbOpts);
-                } else {
-                    String fromKey = "";
-                    String endKey = "";
-                    int metaVersion = 0;
-                    if (cmd.hasOption('f') || cmd.hasOption("from")) {
-                        fromKey = cmd.getOptionValue("from");
-                        if (Strings.isNullOrEmpty(fromKey)) {
-                            System.err.println("from key is missing");
-                            System.exit(-1);
-                        }
+                }
+                String fromKey = "";
+                String endKey = "";
+                int metaVersion = 0;
+                if (cmd.hasOption('f') || cmd.hasOption("from")) {
+                    fromKey = cmd.getOptionValue("from");
+                    if (Strings.isNullOrEmpty(fromKey)) {
+                        System.err.println("from key is missing");
+                        System.exit(-1);
                     }
-                    if (cmd.hasOption('t') || cmd.hasOption("to")) {
-                        endKey = cmd.getOptionValue("to");
-                        if (Strings.isNullOrEmpty(endKey)) {
-                            System.err.println("end key is missing");
-                            System.exit(-1);
-                        }
+                }
+                if (cmd.hasOption('t') || cmd.hasOption("to")) {
+                    endKey = cmd.getOptionValue("to");
+                    if (Strings.isNullOrEmpty(endKey)) {
+                        System.err.println("end key is missing");
+                        System.exit(-1);
                     }
-                    if (cmd.hasOption('m') || cmd.hasOption("metaversion")) {
-                        try {
-                            metaVersion = Integer.valueOf(cmd.getOptionValue("metaversion"));
-                        } catch (NumberFormatException e) {
-                            System.err.println("Invalid meta version format");
-                            System.exit(-1);
-                        }
+                }
+                if (cmd.hasOption('m') || cmd.hasOption("metaversion")) {
+                    try {
+                        metaVersion = Integer.valueOf(cmd.getOptionValue("metaversion"));
+                    } catch (NumberFormatException e) {
+                        System.err.println("Invalid meta version format");
+                        System.exit(-1);
                     }
-
-                    BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, false, fromKey, endKey, metaVersion);
-                    return new CommandLineOptions(false, "", bdbOpts);
+                }
+                
+                BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, false, fromKey, endKey, metaVersion);
+                return new CommandLineOptions(false, "", bdbOpts);
                 }
             } else {
                 System.err.println("Invalid options when running bdb je tools");
                 System.exit(-1);
             }
-        } else if (cmd.hasOption('h') || cmd.hasOption("helper")) {
-            String helperNode = cmd.getOptionValue("helper");
-            if (Strings.isNullOrEmpty(helperNode)) {
-                System.err.println("Missing helper node");
-                System.exit(-1);
-            }
-            return new CommandLineOptions(false, helperNode, null);
         }
 
         // helper node is null, means no helper node is specified

Review comment:
       The annotation here is to explain the 2nd param of `CommandLineOptions`




-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] jackwener commented on pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
jackwener commented on pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302#issuecomment-986064135


   Formatter check failed, I don't locate the error of format.
   
   I use `IDEA checkstyle` with `checkstyle.xml`. It doesn't seem right now.


-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] jackwener commented on a change in pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
jackwener commented on a change in pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302#discussion_r762445660



##########
File path: fe/fe-core/src/main/java/org/apache/doris/PaloFe.java
##########
@@ -232,63 +232,67 @@ private static CommandLineOptions parseArgs(String[] args) {
         // version
         if (cmd.hasOption('v') || cmd.hasOption("version")) {
             return new CommandLineOptions(true, "", null);
-        } else if (cmd.hasOption('b') || cmd.hasOption("bdb")) {
+        }
+        // helper
+        if (cmd.hasOption('h') || cmd.hasOption("helper")) {
+            String helperNode = cmd.getOptionValue("helper");
+            if (Strings.isNullOrEmpty(helperNode)) {
+                System.err.println("Missing helper node");
+                System.exit(-1);
+            }
+            return new CommandLineOptions(false, helperNode, null);
+        }
+
+        if (cmd.hasOption('b') || cmd.hasOption("bdb")) {
             if (cmd.hasOption('l') || cmd.hasOption("listdb")) {
                 // list bdb je databases
                 BDBToolOptions bdbOpts = new BDBToolOptions(true, "", false, "", "", 0);
                 return new CommandLineOptions(false, "", bdbOpts);
-            } else if (cmd.hasOption('d') || cmd.hasOption("db")) {
+            } 
+            if (cmd.hasOption('d') || cmd.hasOption("db")) {
                 // specify a database
                 String dbName = cmd.getOptionValue("db");
                 if (Strings.isNullOrEmpty(dbName)) {
                     System.err.println("BDBJE database name is missing");
                     System.exit(-1);
                 }
-
                 if (cmd.hasOption('s') || cmd.hasOption("stat")) {
                     BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, true, "", "", 0);
                     return new CommandLineOptions(false, "", bdbOpts);
-                } else {
-                    String fromKey = "";
-                    String endKey = "";
-                    int metaVersion = 0;
-                    if (cmd.hasOption('f') || cmd.hasOption("from")) {
-                        fromKey = cmd.getOptionValue("from");
-                        if (Strings.isNullOrEmpty(fromKey)) {
-                            System.err.println("from key is missing");
-                            System.exit(-1);
-                        }
+                }
+                String fromKey = "";
+                String endKey = "";
+                int metaVersion = 0;
+                if (cmd.hasOption('f') || cmd.hasOption("from")) {
+                    fromKey = cmd.getOptionValue("from");
+                    if (Strings.isNullOrEmpty(fromKey)) {
+                        System.err.println("from key is missing");
+                        System.exit(-1);
                     }
-                    if (cmd.hasOption('t') || cmd.hasOption("to")) {
-                        endKey = cmd.getOptionValue("to");
-                        if (Strings.isNullOrEmpty(endKey)) {
-                            System.err.println("end key is missing");
-                            System.exit(-1);
-                        }
+                }
+                if (cmd.hasOption('t') || cmd.hasOption("to")) {
+                    endKey = cmd.getOptionValue("to");
+                    if (Strings.isNullOrEmpty(endKey)) {
+                        System.err.println("end key is missing");
+                        System.exit(-1);
                     }
-                    if (cmd.hasOption('m') || cmd.hasOption("metaversion")) {
-                        try {
-                            metaVersion = Integer.valueOf(cmd.getOptionValue("metaversion"));
-                        } catch (NumberFormatException e) {
-                            System.err.println("Invalid meta version format");
-                            System.exit(-1);
-                        }
+                }
+                if (cmd.hasOption('m') || cmd.hasOption("metaversion")) {
+                    try {
+                        metaVersion = Integer.valueOf(cmd.getOptionValue("metaversion"));
+                    } catch (NumberFormatException e) {
+                        System.err.println("Invalid meta version format");
+                        System.exit(-1);
                     }
-
-                    BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, false, fromKey, endKey, metaVersion);
-                    return new CommandLineOptions(false, "", bdbOpts);
+                }
+                
+                BDBToolOptions bdbOpts = new BDBToolOptions(false, dbName, false, fromKey, endKey, metaVersion);
+                return new CommandLineOptions(false, "", bdbOpts);
                 }
             } else {
                 System.err.println("Invalid options when running bdb je tools");
                 System.exit(-1);
             }
-        } else if (cmd.hasOption('h') || cmd.hasOption("helper")) {
-            String helperNode = cmd.getOptionValue("helper");
-            if (Strings.isNullOrEmpty(helperNode)) {
-                System.err.println("Missing helper node");
-                System.exit(-1);
-            }
-            return new CommandLineOptions(false, helperNode, null);
         }
 
         // helper node is null, means no helper node is specified

Review comment:
       This annotation is confusing. I think it's wrong because the last `return` isn't related with `helper node`




-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302#issuecomment-989465712






-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman merged pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302


   


-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] jackwener commented on pull request #7302: [refactor] modify the control flow code to improve code readability

Posted by GitBox <gi...@apache.org>.
jackwener commented on pull request #7302:
URL: https://github.com/apache/incubator-doris/pull/7302#issuecomment-986472225


   @yangzhg PTAL. Thanks!


-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org