You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/01/23 08:30:20 UTC

[incubator-iotdb] branch fix_sonar updated: change iotdb-cli according to sonar

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

dope pushed a commit to branch fix_sonar
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/fix_sonar by this push:
     new 9326ceb  change iotdb-cli according to sonar
     new 35e98ec  Merge branch 'fix_sonar' of github.com:apache/incubator-iotdb into fix_sonar
9326ceb is described below

commit 9326ceb142700838885189a101258d6d50bb6230
Author: MyXOF <xu...@163.com>
AuthorDate: Wed Jan 23 16:28:11 2019 +0800

    change iotdb-cli according to sonar
---
 .../apache/iotdb/cli/client/AbstractClient.java    | 34 ++++----
 .../java/org/apache/iotdb/cli/client/Client.java   | 99 ++++++++--------------
 .../org/apache/iotdb/cli/client/WinClient.java     | 95 ++++++++-------------
 .../org/apache/iotdb/cli/tool/AbstractCsvTool.java |  3 +-
 .../org/apache/iotdb/cli/tool/CsvTestDataGen.java  |  1 -
 .../java/org/apache/iotdb/cli/tool/ExportCsv.java  | 29 +++----
 .../java/org/apache/iotdb/cli/tool/ImportCsv.java  | 13 +--
 .../apache/iotdb/cli/client/AbstractClientIT.java  | 89 +++++++------------
 .../iotdb/cli/client/StartClientScriptIT.java      |  4 +-
 9 files changed, 137 insertions(+), 230 deletions(-)

diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
index 0dcb9f2..d19a8c4 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
@@ -61,7 +61,6 @@ public abstract class AbstractClient {
   protected static final String USERNAME_NAME = "username";
 
   protected static final String ISO8601_ARGS = "disableISO8601";
-  // protected static final String TIME_KEY_WORD = "time";
   protected static final List<String> AGGREGRATE_TIME_LIST = new ArrayList<>();
   protected static final String MAX_PRINT_ROW_COUNT_ARGS = "maxPRC";
   protected static final String MAX_PRINT_ROW_COUNT_NAME = "maxPrintRowCount";
@@ -84,7 +83,8 @@ public abstract class AbstractClient {
   protected static final String IMPORT_CMD = "import";
   protected static final String EXPORT_CMD = "export";
   private static final String NEED_NOT_TO_PRINT_TIMESTAMP = "AGGREGATION";
-  protected static String timeFormat = "default";
+  private static final String DEFAULT_TIME_FORMAT = "default";
+  protected static String timeFormat = DEFAULT_TIME_FORMAT;
   protected static int maxPrintRowCount = 1000;
   protected static int fetchSize = 10000;
   protected static int maxTimeLength = ISO_DATETIME_LEN;
@@ -132,7 +132,7 @@ public abstract class AbstractClient {
   protected static int[] maxValueLengthForShow = new int[]{75, 45, 8, 8};
   protected static String formatTime = "%" + maxTimeLength + "s|";
   protected static String formatValue = "%" + maxValueLength + "s|";
-  protected static int DIVIDING_LINE_LEN = 40;
+  protected static int dividinglinelen = 40;
   protected static String host = "127.0.0.1";
   protected static String port = "6667";
   protected static String username;
@@ -159,11 +159,10 @@ public abstract class AbstractClient {
    *
    * @param res result set
    * @param printToConsole print to console
-   * @param statement statement in string format
    * @param zoneId time-zone ID
    * @throws SQLException SQLException
    */
-  public static void output(ResultSet res, boolean printToConsole, String statement, ZoneId zoneId)
+  public static void output(ResultSet res, boolean printToConsole, ZoneId zoneId)
       throws SQLException {
     int cnt = 0;
     int displayCnt = 0;
@@ -175,8 +174,7 @@ public abstract class AbstractClient {
 
     boolean isShow = res instanceof IoTDBMetadataResultSet;
     if (!isShow && resultSetMetaData.getColumnTypeName(0) != null) {
-      printTimestamp = !res.getMetaData().getColumnTypeName(0).toUpperCase()
-          .equals(NEED_NOT_TO_PRINT_TIMESTAMP);
+      printTimestamp = !res.getMetaData().getColumnTypeName(0).equalsIgnoreCase(NEED_NOT_TO_PRINT_TIMESTAMP);
     }
 
     // Output values
@@ -248,7 +246,7 @@ public abstract class AbstractClient {
       }
     }
 
-    System.out.println(StringUtils.repeat('-', DIVIDING_LINE_LEN));
+    System.out.println(StringUtils.repeat('-', dividinglinelen));
     if (isShow) {
       int type = res.getType();
       if (type == IoTDBMetadataResultSet.MetadataType.STORAGE_GROUP.ordinal()) { // storage group
@@ -304,7 +302,7 @@ public abstract class AbstractClient {
       case "long":
       case "number":
         return timestamp + "";
-      case "default":
+      case DEFAULT_TIME_FORMAT:
       case "iso8601":
         dateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), zoneId);
         return dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
@@ -343,7 +341,7 @@ public abstract class AbstractClient {
         maxTimeLength = maxValueLength;
         timeFormat = newTimeFormat.trim().toLowerCase();
         break;
-      case "default":
+      case DEFAULT_TIME_FORMAT:
       case "iso8601":
         maxTimeLength = ISO_DATETIME_LEN;
         timeFormat = newTimeFormat.trim().toLowerCase();
@@ -424,7 +422,7 @@ public abstract class AbstractClient {
         System.out.printf(formatValue, resultSetMetaData.getColumnLabel(i));
       }
     }
-    System.out.printf("\n");
+    System.out.printf("%n");
   }
 
   protected static String[] removePasswordArgs(String[] args) {
@@ -435,11 +433,9 @@ public abstract class AbstractClient {
         break;
       }
     }
-    if (index >= 0) {
-      if ((index + 1 >= args.length) || (index + 1 < args.length && keywordSet
-          .contains(args[index + 1]))) {
-        return ArrayUtils.remove(args, index);
-      }
+    if (index >= 0 && ((index + 1 >= args.length) || (index + 1 < args.length && keywordSet
+        .contains(args[index + 1])))) {
+      return ArrayUtils.remove(args, index);
     }
     return args;
   }
@@ -454,7 +450,7 @@ public abstract class AbstractClient {
         + "                                           \n");
   }
 
-  protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) {
+  protected static OperationResult handleInputCmd(String cmd, IoTDBConnection connection) {
     String specialCmd = cmd.toLowerCase().trim();
 
     if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) {
@@ -462,7 +458,7 @@ public abstract class AbstractClient {
       return OperationResult.RETURN_OPER;
     }
     if (specialCmd.equals(HELP)) {
-      System.out.println(String.format("    <your-sql>\t\t\t execute your sql statment"));
+      System.out.println("    <your-sql>\t\t\t execute your sql statment");
       System.out
           .println(String
               .format("    %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND));
@@ -608,7 +604,7 @@ public abstract class AbstractClient {
       boolean hasResultSet = statement.execute(cmd.trim());
       if (hasResultSet) {
         ResultSet resultSet = statement.getResultSet();
-        output(resultSet, printToConsole, cmd.trim(), zoneId);
+        output(resultSet, printToConsole, zoneId);
       }
       System.out.println("Execute successfully. Type `help` to get more information.");
     } catch (Exception e) {
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
index acd6331..e4f12b2 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
@@ -77,7 +77,6 @@ public class Client extends AbstractClient {
    */
   public static void main(String[] args) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
-    IoTDBConnection connection = null;
     Options options = createOptions();
     HelpFormatter hf = new HelpFormatter();
     hf.setWidth(MAX_HELP_CONSOLE_WIDTH);
@@ -121,82 +120,54 @@ public class Client extends AbstractClient {
       return;
     }
 
-    ConsoleReader reader = null;
-    try {
-      reader = new ConsoleReader();
+    try(ConsoleReader reader = new ConsoleReader()) {
       reader.setExpandEvents(false);
-      // for (Completer completer : getCommandCompleter()) {
-      // reader.addCompleter(completer);
-      // }
-      // ((CandidateListCompletionHandler) reader.getCompletionHandler())
-      // .setPrintSpaceAfterFullCompletion(false);
       String s;
-      try {
-        host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
-        port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
-        username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
 
-        password = commandLine.getOptionValue(PASSWORD_ARGS);
-        if (password == null) {
-          password = reader.readLine("please input your password:", '\0');
-        }
-        try {
-          connection = (IoTDBConnection) DriverManager
-              .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password);
-          properties = connection.getServerProperties();
-          AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
-        } catch (SQLException e) {
-          System.out.println(String.format("%s> %s. Host is %s, port is %s.", IOTDB_CLI_PREFIX,
-              e.getMessage(), host, port));
-          return;
-        }
+      host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
+      port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
+      username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
 
-      } catch (ArgsErrorException e) {
-        // System.out.println(TSFILEDB_CLI_PREFIX + ": " + e.getMessage());
-        return;
+      password = commandLine.getOptionValue(PASSWORD_ARGS);
+      if (password == null) {
+        password = reader.readLine("please input your password:", '\0');
       }
-
-      displayLogo(properties.getVersion());
-      System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
-
-      while (true) {
-        s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
-        if (s == null) {
-          continue;
-        } else {
-          String[] cmds = s.trim().split(";");
-          for (int i = 0; i < cmds.length; i++) {
-            String cmd = cmds[i];
-            if (cmd != null && !cmd.trim().equals("")) {
-              OperationResult result = handleInputInputCmd(cmd, connection);
-              switch (result) {
-                case RETURN_OPER:
-                  return;
-                case CONTINUE_OPER:
-                  continue;
-                default:
-                  break;
+      try (IoTDBConnection connection = (IoTDBConnection) DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)){
+        properties = connection.getServerProperties();
+        AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
+        displayLogo(properties.getVersion());
+        System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
+        while (true) {
+          s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
+          if (s != null) {
+            String[] cmds = s.trim().split(";");
+            for (int i = 0; i < cmds.length; i++) {
+              String cmd = cmds[i];
+              if (cmd != null && !cmd.trim().equals("")) {
+                OperationResult result = handleInputCmd(cmd, connection);
+                switch (result) {
+                  case RETURN_OPER:
+                    return;
+                  case CONTINUE_OPER:
+                    continue;
+                  default:
+                    break;
+                }
               }
             }
           }
         }
+      } catch (SQLException e) {
+        System.out.println(String.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host, port));
       }
-    } catch (Exception e) {
+    } catch(ArgsErrorException e){
+      System.out.println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
+    }catch (Exception e) {
       System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
-    } finally {
-      if (reader != null) {
-        reader.close();
-      }
-      if (connection != null) {
-        try {
-          connection.close();
-        } catch (SQLException e) {
-          e.printStackTrace();
-        }
-      }
     }
   }
 
+  @Deprecated
   private static Completer[] getCommandCompleter() {
     List<String> candidateStrings = new ArrayList<>();
     for (String s : FUNCTION_NAME_LIST) {
@@ -296,7 +267,7 @@ public class Client extends AbstractClient {
           final List<CharSequence> candidates) {
         int result = super.complete(buffer, cursor, candidates);
         if (candidates.isEmpty() && cursor > 1) {
-          int equalsIdx = buffer.indexOf("=");
+          int equalsIdx = buffer.indexOf('=');
           if (equalsIdx != -1) {
             String confName = buffer.substring(0, equalsIdx);
             String value = buffer.substring(equalsIdx + 1).toUpperCase();
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
index 1103b9a..cf3473f 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
@@ -41,7 +41,6 @@ public class WinClient extends AbstractClient {
    */
   public static void main(String[] args) throws ClassNotFoundException, SQLException {
     Class.forName(Config.JDBC_DRIVER_NAME);
-    IoTDBConnection connection = null;
     Options options = createOptions();
     HelpFormatter hf = new HelpFormatter();
     hf.setWidth(MAX_HELP_CONSOLE_WIDTH);
@@ -84,70 +83,50 @@ public class WinClient extends AbstractClient {
       hf.printHelp(IOTDB_CLI_PREFIX, options, true);
       return;
     }
-    Scanner scanner = null;
-    try {
-      String s;
-
-      try {
-        host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
-        port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
-        username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
 
-        password = commandLine.getOptionValue(PASSWORD_ARGS);
-        if (password == null) {
-          password = readPassword();
-        }
-        try {
-          connection = (IoTDBConnection) DriverManager
-              .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password);
-          properties = connection.getServerProperties();
-          AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
-        } catch (SQLException e) {
-          System.out.println(IOTDB_CLI_PREFIX + "> " + e.getMessage());
-          return;
-        }
-      } catch (ArgsErrorException e) {
-        // System.out.println(TSFILEDB_CLI_PREFIX + ": " + e.getMessage());
-        return;
+    try (Scanner scanner = new Scanner(System.in)){
+      host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
+      port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
+      username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
+      password = commandLine.getOptionValue(PASSWORD_ARGS);
+      if (password == null) {
+        password = readPassword();
       }
-
-      displayLogo(properties.getVersion());
-
-      System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
-      scanner = new Scanner(System.in);
-      while (true) {
-        System.out.print(IOTDB_CLI_PREFIX + "> ");
-        s = scanner.nextLine();
-        if (s == null) {
-          continue;
-        } else {
-          String[] cmds = s.trim().split(";");
-          for (int i = 0; i < cmds.length; i++) {
-            String cmd = cmds[i];
-            if (cmd != null && !cmd.trim().equals("")) {
-              OperationResult result = handleInputInputCmd(cmd, connection);
-              switch (result) {
-                case RETURN_OPER:
-                  return;
-                case CONTINUE_OPER:
-                  continue;
-                default:
-                  break;
+      try(IoTDBConnection connection = (IoTDBConnection) DriverManager
+                .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)){
+        properties = connection.getServerProperties();
+        AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
+        displayLogo(properties.getVersion());
+        System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
+        while (true) {
+          System.out.print(IOTDB_CLI_PREFIX + "> ");
+          String s = scanner.nextLine();
+          if(s != null){
+            String[] cmds = s.trim().split(";");
+            for (int i = 0; i < cmds.length; i++) {
+              String cmd = cmds[i];
+              if (cmd != null && !cmd.trim().equals("")) {
+                OperationResult result = handleInputCmd(cmd, connection);
+                switch (result) {
+                  case RETURN_OPER:
+                    return;
+                  case CONTINUE_OPER:
+                    continue;
+                  default:
+                    break;
+                }
               }
             }
           }
         }
+			} catch (SQLException e) {
+        System.out.println(String.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host, port));
       }
-    } catch (Exception e) {
-      System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
-    } finally {
-      if (scanner != null) {
-        scanner.close();
-      }
-      if (connection != null) {
-        connection.close();
-      }
-    }
+    } catch (ArgsErrorException e) {
+      System.out.println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
+    }catch (Exception e) {
+    	System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
+	  }
   }
 
   private static String readPassword() {
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/AbstractCsvTool.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/AbstractCsvTool.java
index 9c798b3..badb8be 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/AbstractCsvTool.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/AbstractCsvTool.java
@@ -68,11 +68,12 @@ public abstract class AbstractCsvTool {
   protected static String password;
   protected static ZoneId zoneId;
 
-  // protected static final String JDBC_DRIVER = "case hu.tsfiledb.jdbc.IoTDBDriver";
   protected static String timeZoneID;
   protected static String timeFormat;
   protected static IoTDBConnection connection;
 
+  AbstractCsvTool() {}
+  
   protected static String checkRequiredArg(String arg, String name, CommandLine commandLine)
       throws ArgsErrorException {
     String str = commandLine.getOptionValue(arg);
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/CsvTestDataGen.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/CsvTestDataGen.java
index fa0736e..24b288d 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/CsvTestDataGen.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/CsvTestDataGen.java
@@ -62,7 +62,6 @@ public class CsvTestDataGen {
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     } catch (IOException e) {
-      // TODO Auto-generated catch block
       e.printStackTrace();
     } finally {
       try {
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
index c503fa5..51ea6b0 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
@@ -149,7 +149,7 @@ public class ExportCsv extends AbstractCsvTool {
   }
 
   private static void parseSpecialParams(CommandLine commandLine, ConsoleReader reader)
-      throws IOException, ArgsErrorException {
+      throws ArgsErrorException {
     targetDirectory = checkRequiredArg(TARGET_FILE_ARGS, TARGET_FILE_NAME, commandLine);
     timeFormat = commandLine.getOptionValue(TIME_FORMAT_ARGS);
     if (timeFormat == null) {
@@ -216,21 +216,19 @@ public class ExportCsv extends AbstractCsvTool {
     return options;
   }
 
-  private static void dumpFromSqlFile(String filePath) throws ClassNotFoundException, IOException {
-    BufferedReader reader = new BufferedReader(new FileReader(filePath));
-    String sql = null;
-    int index = 0;
-    while ((sql = reader.readLine()) != null) {
-      try {
-        dumpResult(sql, index);
-      } catch (SQLException e) {
-        System.out.println(
-            String.format("[ERROR] Cannot dump data for statment %s, because %s", sql,
-                e.getMessage()));
+  private static void dumpFromSqlFile(String filePath) throws IOException {
+    try (BufferedReader reader = new BufferedReader(new FileReader(filePath));){
+      String sql = null;
+      int index = 0;
+      while ((sql = reader.readLine()) != null) {
+        try {
+          dumpResult(sql, index);
+        } catch (SQLException e) {
+          System.out.println(String.format("[ERROR] Cannot dump data for statment %s, because %s", sql, e.getMessage()));
+        }
+        index++;
       }
-      index++;
     }
-    reader.close();
   }
 
   /**
@@ -238,11 +236,10 @@ public class ExportCsv extends AbstractCsvTool {
    *
    * @param sql export the result of executing the sql
    * @param index use to create dump file name
-   * @throws ClassNotFoundException if cannot find driver
    * @throws SQLException if SQL is not valid
    */
   private static void dumpResult(String sql, int index)
-      throws ClassNotFoundException, SQLException {
+      throws SQLException {
     BufferedWriter writer = null;
     final String path = targetDirectory + DUMP_FILE_NAME + index + ".csv";
     try {
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
index 2bd9734..813ebb9 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
@@ -170,14 +170,14 @@ public class ImportCsv extends AbstractCsvTool {
           return;
         }
         headInfo.add(strHeadInfo[i]);
-        String deviceInfo = strHeadInfo[i].substring(0, strHeadInfo[i].lastIndexOf("."));
+        String deviceInfo = strHeadInfo[i].substring(0, strHeadInfo[i].lastIndexOf('.'));
 
         if (!deviceToColumn.containsKey(deviceInfo)) {
           deviceToColumn.put(deviceInfo, new ArrayList<>());
         }
         // storage every device's sensor index info
         deviceToColumn.get(deviceInfo).add(i - 1);
-        colInfo.add(strHeadInfo[i].substring(strHeadInfo[i].lastIndexOf(".") + 1));
+        colInfo.add(strHeadInfo[i].substring(strHeadInfo[i].lastIndexOf('.') + 1));
       }
 
       String line;
@@ -301,10 +301,6 @@ public class ImportCsv extends AbstractCsvTool {
       String timestampsStr = data[0];
       sbd.append(") values(").append(timestampsStr.trim().equals("")
           ? "NO TIMESTAMP" : timestampsStr);
-      // if (timestampsStr.trim().equals("")) {
-      // continue;
-      // }
-      // sbd.append(") values(").append(timestampsStr);
 
       for (int j = 0; j < colIndex.size(); ++j) {
         if (data[entry.getValue().get(j) + 1].equals("")) {
@@ -356,7 +352,7 @@ public class ImportCsv extends AbstractCsvTool {
         hf.printHelp(TSFILEDB_CLI_PREFIX, options, true);
         return;
       }
-      parseSpecialParams(commandLine, reader);
+      parseSpecialParams(commandLine);
       importCsvFromFile(host, port, username, password, filename, timeZoneID);
     } catch (ArgsErrorException e) {
       // ignored
@@ -367,8 +363,7 @@ public class ImportCsv extends AbstractCsvTool {
     }
   }
 
-  private static void parseSpecialParams(CommandLine commandLine, ConsoleReader reader)
-      throws IOException, ArgsErrorException {
+  private static void parseSpecialParams(CommandLine commandLine) {
     timeZoneID = commandLine.getOptionValue(TIME_ZONE_ARGS);
   }
 
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
index 899f615..275bb9b 100644
--- a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
@@ -81,27 +81,27 @@ public class AbstractClientIT {
     String str = AbstractClient
         .checkRequiredArg(AbstractClient.USERNAME_ARGS, AbstractClient.USERNAME_NAME,
             commandLine, true, "root");
-    assertEquals(str, "user1");
+    assertEquals("user1", str);
 
     args = new String[]{"-u", "root",};
     commandLine = parser.parse(options, args);
     str = AbstractClient
         .checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine, false,
             "127.0.0.1");
-    assertEquals(str, "127.0.0.1");
+    assertEquals("127.0.0.1", str);
     try {
       str = AbstractClient
           .checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine, true,
               "127.0.0.1");
     } catch (ArgsErrorException e) {
-      assertEquals(e.getMessage(), "IoTDB: Required values for option 'host' not provided");
+      assertEquals("IoTDB: Required values for option 'host' not provided", e.getMessage());
     }
     try {
       str = AbstractClient
           .checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine,
               false, null);
     } catch (ArgsErrorException e) {
-      assertEquals(e.getMessage(), "IoTDB: Required values for option 'host' is null.");
+      assertEquals("IoTDB: Required values for option 'host' is null.", e.getMessage());
     }
   }
 
@@ -141,61 +141,30 @@ public class AbstractClientIT {
 
   @Test
   public void testHandleInputInputCmd() {
-    assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.EXIT_COMMAND, connection),
-        OperationResult.RETURN_OPER);
-    assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.QUIT_COMMAND, connection),
-        OperationResult.RETURN_OPER);
-
-    assertEquals(
-        AbstractClient.handleInputInputCmd(AbstractClient.SHOW_METADATA_COMMAND, connection),
-        OperationResult.CONTINUE_OPER);
-
-    assertEquals(AbstractClient
-        .handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIMESTAMP_DISPLAY),
-            connection), OperationResult.CONTINUE_OPER);
-    assertEquals(AbstractClient
-        .handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_TIMESTAMP_DISPLAY),
-            connection), OperationResult.CONTINUE_OPER);
-    assertEquals(AbstractClient
-            .handleInputInputCmd(String.format("%s=default", AbstractClient.SET_TIMESTAMP_DISPLAY),
-                connection),
-        OperationResult.CONTINUE_OPER);
+    assertEquals(OperationResult.RETURN_OPER, AbstractClient.handleInputCmd(AbstractClient.EXIT_COMMAND, connection));
+    assertEquals(OperationResult.RETURN_OPER, AbstractClient.handleInputCmd(AbstractClient.QUIT_COMMAND, connection));
+
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(AbstractClient.SHOW_METADATA_COMMAND, connection));
+
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=", AbstractClient.SET_TIMESTAMP_DISPLAY), connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=xxx", AbstractClient.SET_TIMESTAMP_DISPLAY), connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=default", AbstractClient.SET_TIMESTAMP_DISPLAY), connection));
     testSetTimeFormat();
 
-    assertEquals(
-        AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_MAX_DISPLAY_NUM),
-            connection), OperationResult.CONTINUE_OPER);
-    assertEquals(AbstractClient
-        .handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_MAX_DISPLAY_NUM),
-            connection), OperationResult.CONTINUE_OPER);
-    assertEquals(AbstractClient
-        .handleInputInputCmd(String.format("%s=1", AbstractClient.SET_MAX_DISPLAY_NUM),
-            connection), OperationResult.CONTINUE_OPER);
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=", AbstractClient.SET_MAX_DISPLAY_NUM), connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=xxx", AbstractClient.SET_MAX_DISPLAY_NUM),connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=1", AbstractClient.SET_MAX_DISPLAY_NUM), connection));
     testSetMaxDisplayNumber();
 
-    assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMEZONE, connection),
-        OperationResult.CONTINUE_OPER);
-    assertEquals(
-        AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMESTAMP_DISPLAY, connection),
-        OperationResult.CONTINUE_OPER);
-    assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_FETCH_SIZE, connection),
-        OperationResult.CONTINUE_OPER);
-
-    assertEquals(AbstractClient
-            .handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIME_ZONE), connection),
-        OperationResult.CONTINUE_OPER);
-    assertEquals(
-        AbstractClient.handleInputInputCmd(String.format("%s=+08:00", AbstractClient.SET_TIME_ZONE),
-            connection), OperationResult.CONTINUE_OPER);
-
-    assertEquals(
-        AbstractClient
-            .handleInputInputCmd(String.format("%s=", AbstractClient.SET_FETCH_SIZE), connection),
-        OperationResult.CONTINUE_OPER);
-    assertEquals(
-        AbstractClient.handleInputInputCmd(String.format("%s=111", AbstractClient.SET_FETCH_SIZE),
-            connection),
-        OperationResult.CONTINUE_OPER);
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(AbstractClient.SHOW_TIMEZONE, connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(AbstractClient.SHOW_TIMESTAMP_DISPLAY, connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(AbstractClient.SHOW_FETCH_SIZE, connection));
+
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=", AbstractClient.SET_TIME_ZONE), connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=+08:00", AbstractClient.SET_TIME_ZONE), connection));
+
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=", AbstractClient.SET_FETCH_SIZE), connection));
+    assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(String.format("%s=111", AbstractClient.SET_FETCH_SIZE), connection));
   }
 
   private void testSetTimeFormat() {
@@ -208,11 +177,11 @@ public class AbstractClientIT {
     assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|");
 
     AbstractClient.setTimeFormat("default");
-    assertEquals(AbstractClient.maxTimeLength, AbstractClient.ISO_DATETIME_LEN);
+    assertEquals(AbstractClient.ISO_DATETIME_LEN, AbstractClient.maxTimeLength);
     assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|");
 
     AbstractClient.setTimeFormat("iso8601");
-    assertEquals(AbstractClient.maxTimeLength, AbstractClient.ISO_DATETIME_LEN);
+    assertEquals(AbstractClient.ISO_DATETIME_LEN, AbstractClient.maxTimeLength);
     assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|");
 
     AbstractClient.setTimeFormat("yyyy-MM-dd HH:mm:ssZZ");
@@ -227,10 +196,10 @@ public class AbstractClientIT {
 
   private void testSetMaxDisplayNumber() {
     AbstractClient.setMaxDisplayNumber("10");
-    assertEquals(AbstractClient.maxPrintRowCount, 10);
+    assertEquals(10, AbstractClient.maxPrintRowCount);
     AbstractClient.setMaxDisplayNumber("111111111111111");
-    assertEquals(AbstractClient.maxPrintRowCount, Integer.MAX_VALUE);
+    assertEquals(Integer.MAX_VALUE, AbstractClient.maxPrintRowCount);
     AbstractClient.setMaxDisplayNumber("-10");
-    assertEquals(AbstractClient.maxPrintRowCount, Integer.MAX_VALUE);
+    assertEquals(Integer.MAX_VALUE, AbstractClient.maxPrintRowCount);
   }
 }
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
index e4883b9..bf717ac 100644
--- a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
@@ -54,7 +54,7 @@ public class StartClientScriptIT {
   private void testStartClientOnWindows() throws IOException {
     final String[] output = {"````````````````````````", "Starting IoTDB Client",
         "````````````````````````",
-        "IoTDB> Connection Error, please check whether the network is available or the server has started.. Host is 127.0.0.1, port is 6668."};
+        "IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
     String dir = getCurrentPath("cmd.exe", "/c", "echo %cd%");
     ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c",
         dir + File.separator + "cli" + File.separator + "bin" + File.separator + "start-client.bat",
@@ -66,7 +66,7 @@ public class StartClientScriptIT {
   private void testStartClientOnUnix() throws IOException {
     final String[] output = {"---------------------", "Starting IoTDB Client",
         "---------------------",
-        "IoTDB> Connection Error, please check whether the network is available or the server has started.. Host is 127.0.0.1, port is 6668."};
+        "IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
     String dir = getCurrentPath("pwd");
     System.out.println(dir);
     ProcessBuilder builder = new ProcessBuilder("sh",