You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ge...@apache.org on 2020/02/08 15:57:03 UTC

[incubator-iotdb] branch client_chache created (now 0e885bd)

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

geniuspig pushed a change to branch client_chache
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 0e885bd  cache result in client.

This branch includes the following new commits:

     new 0e885bd  cache result in client.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: cache result in client.

Posted by ge...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0e885bd1523fb27b0f350f69d91b55e33bdde2a9
Author: zhutianci <zh...@gmail.com>
AuthorDate: Sat Feb 8 23:56:41 2020 +0800

    cache result in client.
---
 .../org/apache/iotdb/client/AbstractClient.java    | 420 +++++----------------
 .../main/java/org/apache/iotdb/client/Client.java  |  15 +-
 .../java/org/apache/iotdb/client/WinClient.java    |  17 +-
 .../iotdb/jdbc/IoTDBNonAlignQueryResultSet.java    |   8 +-
 4 files changed, 113 insertions(+), 347 deletions(-)

diff --git a/client/src/main/java/org/apache/iotdb/client/AbstractClient.java b/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
index df0d2c9..503355c 100644
--- a/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
+++ b/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
@@ -82,67 +82,17 @@ public abstract class AbstractClient {
   static final String TIMESTAMP_STR = "Time";
   static final int ISO_DATETIME_LEN = 35;
   private static final String IMPORT_CMD = "import";
-  private static final String NEED_NOT_TO_PRINT_TIMESTAMP = "AGGREGATION";
   private static final String DEFAULT_TIME_FORMAT = "default";
   private static String timeFormat = DEFAULT_TIME_FORMAT;
   static int maxPrintRowCount = 100000;
   private static int fetchSize = 10000;
   static int maxTimeLength = ISO_DATETIME_LEN;
   static int maxValueLength = 15;
-  private static int deviceColumnLength = 20; // for GROUP_BY_DEVICE sql
-  private static int measurementColumnLength = 10; // for GROUP_BY_DEVICE sql
-  // for GROUP_BY_DEVICE sql; this name should be the same as that used in server
-  private static String GROUPBY_DEVICE_COLUMN_NAME = "Device";
-  private static boolean isQuit = false;
   static String TIMESTAMP_PRECISION = "ms";
 
-  private static final int START_PRINT_INDEX = 2;
-  private static final int NO_ALIGN_PRINT_INTERVAL = 2;
-
-  /**
-   * control the width of columns for 'show timeseries path' and 'show storage group'.
-   * <p>
-   * for 'show timeseries path':
-   * <table>
-   * <tr>
-   * <th>Timeseries (width:75)</th>
-   * <th>Storage Group (width:45)</th>
-   * <th>DataType width:8)</th>
-   * <th>Encoding (width:8)</th>
-   * </tr>
-   * <tr>
-   * <td>root.vehicle.d1.s1</td>
-   * <td>root.vehicle</td>
-   * <td>INT32</td>
-   * <td>PLAIN</td>
-   * </tr>
-   * <tr>
-   * <td>...</td>
-   * <td>...</td>
-   * <td>...</td>
-   * <td>...</td>
-   * </tr>
-   * </table>
-   * </p>
-   * <p>
-   * for "show storage group path":
-   * <table>
-   * <tr>
-   * <th>STORAGE_GROUP (width:75)</th>
-   * </tr>
-   * <tr>
-   * <td>root.vehicle</td>
-   * </tr>
-   * <tr>
-   * <td>...</td>
-   * </tr>
-   * </table>
-   * </p>
-   */
-  private static int[] maxValueLengthForShow = new int[]{75, 45, 8, 8};
+  private static boolean isReachMaxLine = false;
+
   static String formatTime = "%" + maxTimeLength + "s|";
-  private static String formatValue = "%" + maxValueLength + "s|";
-  private static final int DIVIDING_LINE_LENGTH = 40;
   static String host = "127.0.0.1";
   static String port = "6667";
   static String username;
@@ -150,21 +100,11 @@ public abstract class AbstractClient {
   static String execute;
   static boolean hasExecuteSQL = false;
 
-  private static boolean printToConsole = true;
-
   static Set<String> keywordSet = new HashSet<>();
 
   static ServerProperties properties = null;
 
-  private static boolean printHeader = false;
-  private static int displayCnt = 0;
-
   private static final PrintStream SCREEN_PRINTER = new PrintStream(System.out);
-  /**
-   * showException is currently fixed to false because the display of exceptions is not elaborate.
-   * We can make it an option in future versions.
-   */
-  private static boolean showException = false;
 
   static void init() {
     keywordSet.add("-" + HOST_ARGS);
@@ -177,58 +117,6 @@ public abstract class AbstractClient {
     keywordSet.add("-" + MAX_PRINT_ROW_COUNT_ARGS);
   }
 
-  /**
-   * Client result output.
-   *
-   * @param res result set
-   * @param printToConsole print to console
-   * @param zoneId time-zone ID
-   * @throws SQLException SQLException
-   */
-  private static void output(ResultSet res, boolean printToConsole, ZoneId zoneId)
-      throws SQLException {
-    int cnt = 0;
-    boolean printTimestamp = true;
-    boolean align = true;
-    displayCnt = 0;
-    printHeader = false;
-    ResultSetMetaData resultSetMetaData = res.getMetaData();
-
-    int colCount = resultSetMetaData.getColumnCount();
-
-    if (res instanceof IoTDBQueryResultSet) {
-      printTimestamp = !((IoTDBQueryResultSet) res).isIgnoreTimeStamp();
-    }
-    else {
-      align = false;
-    }
-
-    // Output values
-    while (cnt < maxPrintRowCount && res.next()) {
-      printRow(printTimestamp, align, colCount, resultSetMetaData, res, zoneId);
-      cnt++;
-      if (!printToConsole && cnt % 10000 == 0) {
-        println(cnt);
-      }
-    }
-
-    if (printToConsole) {
-      if (!printHeader) {
-        printBlockLine(printTimestamp, align, colCount, resultSetMetaData);
-        printName(printTimestamp, align, colCount, resultSetMetaData);
-        printBlockLine(printTimestamp, align, colCount, resultSetMetaData);
-      } else {
-        printBlockLine(printTimestamp, align, colCount, resultSetMetaData);
-      }
-
-    }
-
-    if(!res.next()){
-        printCount(cnt);
-    } else {
-        println(String.format("Reach maxPrintRowCount = %s lines", maxPrintRowCount));
-    }
-  }
 
   private static String getTimestampPrecision() {
     return TIMESTAMP_PRECISION;
@@ -238,109 +126,6 @@ public abstract class AbstractClient {
       println("Total line number = " + cnt);
   }
 
-  private static void printRow(boolean printTimestamp, boolean align, int colCount,
-      ResultSetMetaData resultSetMetaData, ResultSet res, ZoneId zoneId)
-      throws SQLException {
-    // Output Labels
-    if (!printToConsole) {
-      return;
-    }
-    printHeader(printTimestamp, align, colCount, resultSetMetaData);
-    printRowData(printTimestamp, align, res, zoneId, resultSetMetaData, colCount);
-  }
-
-  private static void printHeader(boolean printTimestamp, boolean align, int colCount,
-      ResultSetMetaData resultSetMetaData) throws SQLException {
-    if (!printHeader) {
-      printBlockLine(printTimestamp, align, colCount, resultSetMetaData);
-      printName(printTimestamp, align, colCount, resultSetMetaData);
-      printBlockLine(printTimestamp, align, colCount, resultSetMetaData);
-      printHeader = true;
-    }
-  }
-
-  private static void printShow(int colCount, ResultSet res) throws SQLException {
-    print("|");
-    for (int i = 1; i <= colCount; i++) {
-      formatValue = "%" + maxValueLengthForShow[i - 1] + "s|";
-      printf(formatValue, res.getString(i));
-    }
-    println();
-  }
-
-  private static void printRowData(boolean printTimestamp, boolean align, ResultSet res, ZoneId zoneId,
-      ResultSetMetaData resultSetMetaData, int colCount)
-      throws SQLException {
-    if (displayCnt < maxPrintRowCount) { // NOTE displayCnt only works on queried data results
-      print("|");
-      if (align) {
-        if (printTimestamp) {
-          printf(formatTime, formatDatetime(res.getLong(TIMESTAMP_STR), zoneId));
-          for (int i = 2; i <= colCount; i++) {
-            printColumnData(resultSetMetaData, true, res, i, zoneId);
-          }
-        } else {
-          for (int i = 1; i <= colCount; i++) {
-            printColumnData(resultSetMetaData, true, res, i, zoneId);
-          }
-        }
-      }
-      else {
-        for (int i = START_PRINT_INDEX; i <= colCount / NO_ALIGN_PRINT_INTERVAL + 1; i++) {
-          if (printTimestamp) {
-            // timeLabel used for indicating the time column.
-            String timeLabel = TIMESTAMP_STR + resultSetMetaData.getColumnLabel(NO_ALIGN_PRINT_INTERVAL * i - START_PRINT_INDEX);
-            try {
-              printf(formatTime, formatDatetime(res.getLong(timeLabel), zoneId));
-            } catch (Exception e) {
-              printf(formatTime, "null");
-              handleException(e);
-            }
-          }
-          printColumnData(resultSetMetaData, false, res, i, zoneId);
-        }
-      }
-      println();
-      displayCnt++;
-    }
-  }
-
-  private static void printColumnData(ResultSetMetaData resultSetMetaData, boolean align,
-      ResultSet res, int i, ZoneId zoneId) throws SQLException {
-    boolean flag = false;
-    for (String timeStr : AGGREGRATE_TIME_LIST) {
-      if (resultSetMetaData.getColumnLabel(i).toUpperCase().contains(timeStr.toUpperCase())) {
-        flag = true;
-        break;
-      }
-    }
-    if (flag) {
-      try {
-        printf(formatValue, formatDatetime(res.getLong(i), zoneId));
-      } catch (Exception e) {
-        printf(formatValue, "null");
-        handleException(e);
-      }
-    } 
-    else if (align) {
-      if (i == 2 && resultSetMetaData.getColumnName(2).equals(GROUPBY_DEVICE_COLUMN_NAME)) {
-        printf("%" + deviceColumnLength + "s|", res.getString(i));
-      } else {
-        printf(formatValue, res.getString(i));
-      }
-    }
-    // for disable align clause
-    else {
-      if (res.getString(i * NO_ALIGN_PRINT_INTERVAL - START_PRINT_INDEX) == null) {
-        //blank space
-        printf(formatValue, "");
-      }
-      else {
-        printf(formatValue, res.getString(i * NO_ALIGN_PRINT_INTERVAL - START_PRINT_INDEX));
-      }
-    }
-  }
-
   static Options createOptions() {
     Options options = new Options();
     Option help = new Option(HELP_ARGS, false, "Display help information(optional)");
@@ -386,40 +171,40 @@ public abstract class AbstractClient {
       long timestamp, ZoneId zoneid, String timestampPrecision) {
     if (timestampPrecision.equals("ms")) {
       long integerofDate = timestamp / 1000;
-      String digits = Long.toString(timestamp % 1000);
+      StringBuilder digits = new StringBuilder(Long.toString(timestamp % 1000));
       ZonedDateTime dateTime = ZonedDateTime
           .ofInstant(Instant.ofEpochSecond(integerofDate), zoneid);
       String datetime = dateTime.format(formatter);
       int length = digits.length();
       if (length != 3) {
         for (int i = 0; i < 3 - length; i++) {
-          digits = "0" + digits;
+          digits.insert(0, "0");
         }
       }
       return datetime.substring(0, 19) + "." + digits + datetime.substring(19);
     } else if (timestampPrecision.equals("us")) {
       long integerofDate = timestamp / 1000_000;
-      String digits = Long.toString(timestamp % 1000_000);
+      StringBuilder digits = new StringBuilder(Long.toString(timestamp % 1000_000));
       ZonedDateTime dateTime = ZonedDateTime
           .ofInstant(Instant.ofEpochSecond(integerofDate), zoneid);
       String datetime = dateTime.format(formatter);
       int length = digits.length();
       if (length != 6) {
         for (int i = 0; i < 6 - length; i++) {
-          digits = "0" + digits;
+          digits.insert(0, "0");
         }
       }
       return datetime.substring(0, 19) + "." + digits + datetime.substring(19);
     } else {
       long integerofDate = timestamp / 1000_000_000L;
-      String digits = Long.toString(timestamp % 1000_000_000L);
+      StringBuilder digits = new StringBuilder(Long.toString(timestamp % 1000_000_000L));
       ZonedDateTime dateTime = ZonedDateTime
           .ofInstant(Instant.ofEpochSecond(integerofDate), zoneid);
       String datetime = dateTime.format(formatter);
       int length = digits.length();
       if (length != 9) {
         for (int i = 0; i < 9 - length; i++) {
-          digits = "0" + digits;
+          digits.insert(0, "0");
         }
       }
       return datetime.substring(0, 19) + "." + digits + datetime.substring(19);
@@ -505,87 +290,6 @@ public abstract class AbstractClient {
     }
   }
 
-  private static void printBlockLine(boolean printTimestamp, boolean align, int colCount,
-      ResultSetMetaData resultSetMetaData) throws SQLException {
-    StringBuilder blockLine = new StringBuilder();
-    if (align) {
-      if (printTimestamp) {
-        blockLine.append("+").append(StringUtils.repeat('-', maxTimeLength)).append("+");
-        if (resultSetMetaData.getColumnName(2).equals(GROUPBY_DEVICE_COLUMN_NAME)) {
-          maxValueLength = measurementColumnLength;
-        } else {
-          int tmp = Integer.MIN_VALUE;
-          for (int i = 1; i <= colCount; i++) {
-            int len = resultSetMetaData.getColumnLabel(i).length();
-            tmp = Math.max(tmp, len);
-          }
-          maxValueLength = tmp;
-        }
-        for (int i = 2; i <= colCount; i++) {
-          if (i == 2 && resultSetMetaData.getColumnName(2).equals(GROUPBY_DEVICE_COLUMN_NAME)) {
-            blockLine.append(StringUtils.repeat('-', deviceColumnLength)).append("+");
-          } else {
-            blockLine.append(StringUtils.repeat('-', maxValueLength)).append("+");
-          }
-        }
-      } else {
-        blockLine.append("+");
-        for (int i = 1; i <= colCount; i++) {
-          blockLine.append(StringUtils.repeat('-', maxValueLength)).append("+");
-        }
-      }
-    }
-    // for disable align clause
-    else {
-      int tmp = Integer.MIN_VALUE;
-      for (int i = 1; i <= colCount; i++) {
-        int len = resultSetMetaData.getColumnLabel(i).length();
-        tmp = Math.max(tmp, len);
-      }
-      maxValueLength = tmp;
-      blockLine.append("+");
-      for (int i = 2; i <= colCount / 2 + 1; i++) {
-        if (printTimestamp) {
-          blockLine.append(StringUtils.repeat('-', maxTimeLength)).append("+");
-        }
-        blockLine.append(StringUtils.repeat('-', maxValueLength)).append("+");
-      }
-    }
-    println(blockLine);
-  }
-
-  private static void printName(boolean printTimestamp, boolean align, int colCount,
-      ResultSetMetaData resultSetMetaData) throws SQLException {
-    print("|");
-    formatValue = "%" + maxValueLength + "s|";
-    if (align) {
-      if (printTimestamp) {
-        printf(formatTime, TIMESTAMP_STR);
-        for (int i = 2; i <= colCount; i++) {
-          if (i == 2 && resultSetMetaData.getColumnName(2).equals(GROUPBY_DEVICE_COLUMN_NAME)) {
-            printf("%" + deviceColumnLength + "s|", resultSetMetaData.getColumnLabel(i));
-          } else {
-            printf(formatValue, resultSetMetaData.getColumnLabel(i));
-          }
-        }
-      } else {
-        for (int i = 1; i <= colCount; i++) {
-          printf(formatValue, resultSetMetaData.getColumnLabel(i));
-        }
-      }
-    }
-    // for disable align
-    else {
-      for (int i = 2; i <= colCount; i += 2) {
-        if (printTimestamp) {
-          printf(formatTime, TIMESTAMP_STR);
-        }
-        printf(formatValue, resultSetMetaData.getColumnLabel(i));
-      }
-    }
-    println();
-  }
-
   static String[] removePasswordArgs(String[] args) {
     int index = -1;
     for (int i = 0; i < args.length; i++) {
@@ -647,7 +351,6 @@ public abstract class AbstractClient {
     String specialCmd = cmd.toLowerCase().trim();
 
     if (QUIT_COMMAND.equals(specialCmd) || EXIT_COMMAND.equals(specialCmd)) {
-      isQuit = true;
       return OperationResult.STOP_OPER;
     }
     if (HELP.equals(specialCmd)) {
@@ -725,7 +428,7 @@ public abstract class AbstractClient {
       setTimeFormat(cmd.split("=")[1]);
     } catch (Exception e) {
       println(String.format("time display format error, %s", e.getMessage()));
-      handleException(e);
+      handleException();
       return;
     }
     println("Time display type has set to " + cmd.split("=")[1].trim());
@@ -742,7 +445,7 @@ public abstract class AbstractClient {
       connection.setTimeZone(cmd.split("=")[1].trim());
     } catch (Exception e) {
       println(String.format("Time zone format error: %s", e.getMessage()));
-      handleException(e);
+      handleException();
       return;
     }
     println("Time zone has set to " + values[1].trim());
@@ -759,7 +462,7 @@ public abstract class AbstractClient {
       setFetchSize(cmd.split("=")[1]);
     } catch (Exception e) {
       println(String.format("Fetch size format error, %s", e.getMessage()));
-      handleException(e);
+      handleException();
       return;
     }
     println("Fetch size has set to " + values[1].trim());
@@ -776,7 +479,7 @@ public abstract class AbstractClient {
       setMaxDisplayNumber(cmd.split("=")[1]);
     } catch (Exception e) {
       println(String.format("Max display number format error, %s", e.getMessage()));
-      handleException(e);
+      handleException();
       return;
     }
     println("Max display number has set to " + values[1].trim());
@@ -787,7 +490,7 @@ public abstract class AbstractClient {
       println("Current time zone: " + connection.getTimeZone());
     } catch (Exception e) {
       println("Cannot get time zone from server side because: " + e.getMessage());
-      handleException(e);
+      handleException();
     }
   }
 
@@ -805,34 +508,102 @@ public abstract class AbstractClient {
     } catch (SQLException e) {
       println(String.format("Failed to import from %s because %s",
           cmd.split(" ")[1], e.getMessage()));
-      handleException(e);
+      handleException();
     } catch (TException e) {
       println("Cannot connect to server");
-      handleException(e);
+      handleException();
     }
   }
 
   private static void executeQuery(IoTDBConnection connection, String cmd) {
     long startTime = System.currentTimeMillis();
-    try (Statement statement = connection.createStatement();) {
+    try (Statement statement = connection.createStatement()) {
       ZoneId zoneId = ZoneId.of(connection.getTimeZone());
       statement.setFetchSize(fetchSize);
       boolean hasResultSet = statement.execute(cmd.trim());
       if (hasResultSet) {
         ResultSet resultSet = statement.getResultSet();
-        output(resultSet, printToConsole, zoneId);
-        if (resultSet != null) {
-          resultSet.close();
-        }
+        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+        int columnLength = resultSetMetaData.getColumnCount();
+        List<Integer> maxSizeList = new ArrayList<>(columnLength);
+        List<List<String>> lists = cacheResult(resultSet,maxSizeList, columnLength, resultSetMetaData, zoneId);
+        output(lists, maxSizeList);
+        resultSet.close();
       }
     } catch (Exception e) {
       println("Msg: " + e.getMessage());
-      handleException(e);
+      handleException();
     }
     long costTime = System.currentTimeMillis() - startTime;
     println(String.format("It costs %.3fs", costTime / 1000.0));
   }
 
+  private static List<List<String>> cacheResult(ResultSet resultSet, List<Integer> maxSizeList,
+      int columnLength, ResultSetMetaData resultSetMetaData, ZoneId zoneId)
+      throws SQLException {
+    boolean printTimestamp = !((IoTDBQueryResultSet) resultSet).isIgnoreTimeStamp();
+    List<List<String>> lists = new ArrayList<>(columnLength);
+    for(int i = 1; i <= columnLength; i++) {
+      List<String> list = new ArrayList<>(30);
+      list.add(resultSetMetaData.getColumnLabel(i));
+      lists.add(list);
+      maxSizeList.add(resultSetMetaData.getColumnLabel(i).length());
+    }
+    int j = 0;
+    while (resultSet.next()) {
+      if(j > maxPrintRowCount) {
+        break;
+      }
+      for(int i = 1; i <= columnLength; i++) {
+        String tmp;
+        if(printTimestamp && i == 1) {
+          tmp = formatDatetime(resultSet.getLong(TIMESTAMP_STR), zoneId);
+        } else {
+          tmp = resultSet.getString(i);
+        }
+        lists.get(i-1).add(tmp);
+        if(maxSizeList.get(i-1) < tmp.length()) {
+          maxSizeList.set(i-1 , tmp.length());
+        }
+      }
+      j++;
+    }
+    isReachMaxLine = resultSet.next();
+    return lists;
+  }
+
+  private static void output(List<List<String>> lists, List<Integer> maxSizeList) {
+    printBlockLine(maxSizeList);
+    printRow(lists,0, maxSizeList);
+    printBlockLine(maxSizeList);
+    for(int i = 1; i < lists.get(0).size(); i++) {
+      printRow(lists, i, maxSizeList);
+    }
+    printBlockLine(maxSizeList);
+    if(!isReachMaxLine) {
+      printCount(lists.get(0).size()-1);
+    } else {
+      println(String.format("Reach maxPrintRowCount = %s lines", maxPrintRowCount));
+    }
+  }
+
+  private static void printBlockLine(List<Integer> maxSizeList) {
+    StringBuilder blockLine = new StringBuilder();
+    for (Integer integer : maxSizeList) {
+      blockLine.append("+").append(StringUtils.repeat("-", integer));
+    }
+    blockLine.append("+");
+    println(blockLine.toString());
+  }
+
+  private static void printRow(List<List<String>> lists, int i, List<Integer> maxSizeList) {
+    printf("|");
+    for (int j = 0; j < maxSizeList.size(); j++) {
+      printf("%"+ maxSizeList.get(j) + "s|", lists.get(j).get(i));
+    }
+    println();
+  }
+
   enum OperationResult {
     STOP_OPER, CONTINUE_OPER, NO_OPER
   }
@@ -853,13 +624,10 @@ public abstract class AbstractClient {
     SCREEN_PRINTER.println(msg);
   }
 
-  private static void println(Object obj) {
-    SCREEN_PRINTER.println(obj);
-  }
-
-  static void handleException(Exception e) {
-    if (showException) {
-      e.printStackTrace(SCREEN_PRINTER);
-    }
+  static void handleException() {
+    /*
+     * showException is currently fixed to false because the display of exceptions is not elaborate.
+     * We can make it an option in future versions.
+     */
   }
 }
diff --git a/client/src/main/java/org/apache/iotdb/client/Client.java b/client/src/main/java/org/apache/iotdb/client/Client.java
index 4b44191..3f8e2fd 100644
--- a/client/src/main/java/org/apache/iotdb/client/Client.java
+++ b/client/src/main/java/org/apache/iotdb/client/Client.java
@@ -95,12 +95,12 @@ public class Client extends AbstractClient {
               + "-h xxx.xxx.xxx.xxx -p xxxx -u xxx.");
       println("For more information, please check the following hint.");
       hf.printHelp(IOTDB_CLI_PREFIX, options, true);
-      handleException(e);
+      handleException();
       return false;
     } catch (NumberFormatException e) {
       println(
           IOTDB_CLI_PREFIX + "> error format of max print row count, it should be number");
-      handleException(e);
+      handleException();
       return false;
     }
     return true;
@@ -126,17 +126,17 @@ public class Client extends AbstractClient {
           processCmd(execute, connection);
           return;
         } catch (SQLException e) {
-          handleException(e);
+          handleException();
         }
       }
 
       receiveCommands(reader);
     } catch (ArgsErrorException e) {
       println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
-      handleException(e);
+      handleException();
     } catch (Exception e) {
       println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
-      handleException(e);
+      handleException();
     }
   }
 
@@ -162,7 +162,7 @@ public class Client extends AbstractClient {
       println(String
           .format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
               port));
-      handleException(e);
+      handleException();
     }
   }
 
@@ -171,8 +171,7 @@ public class Client extends AbstractClient {
       return true;
     }
     String[] cmds = s.trim().split(";");
-    for (int i = 0; i < cmds.length; i++) {
-      String cmd = cmds[i];
+    for (String cmd : cmds) {
       if (cmd != null && !"".equals(cmd.trim())) {
         OperationResult result = handleInputCmd(cmd, connection);
         switch (result) {
diff --git a/client/src/main/java/org/apache/iotdb/client/WinClient.java b/client/src/main/java/org/apache/iotdb/client/WinClient.java
index e52ebf0..9ede7c8 100644
--- a/client/src/main/java/org/apache/iotdb/client/WinClient.java
+++ b/client/src/main/java/org/apache/iotdb/client/WinClient.java
@@ -42,7 +42,7 @@ public class WinClient extends AbstractClient {
    *
    * @param args -console args
    */
-  public static void main(String[] args) throws ClassNotFoundException, SQLException {
+  public static void main(String[] args) throws ClassNotFoundException {
     Class.forName(Config.JDBC_DRIVER_NAME);
     Options options = createOptions();
     HelpFormatter hf = new HelpFormatter();
@@ -92,7 +92,7 @@ public class WinClient extends AbstractClient {
         setTimeFormat("long");
       }
       if (commandLine.hasOption(MAX_PRINT_ROW_COUNT_ARGS)) {
-        maxPrintRowCount = Integer.valueOf(commandLine.getOptionValue(MAX_PRINT_ROW_COUNT_ARGS));
+        maxPrintRowCount = Integer.parseInt(commandLine.getOptionValue(MAX_PRINT_ROW_COUNT_ARGS));
         if (maxPrintRowCount < 0) {
           maxPrintRowCount = Integer.MAX_VALUE;
         }
@@ -100,12 +100,12 @@ public class WinClient extends AbstractClient {
     } catch (ParseException e) {
       println("Require more params input, please check the following hint.");
       hf.printHelp(IOTDB_CLI_PREFIX, options, true);
-      handleException(e);
+      handleException();
       return false;
     } catch (NumberFormatException e) {
       println(
           IOTDB_CLI_PREFIX + "> error format of max print row count, it should be number");
-      handleException(e);
+      handleException();
       return false;
     }
     return true;
@@ -123,10 +123,10 @@ public class WinClient extends AbstractClient {
       receiveCommands(scanner);
     } catch (ArgsErrorException e) {
       println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
-      handleException(e);
+      handleException();
     } catch (Exception e) {
       println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
-      handleException(e);
+      handleException();
     }
   }
 
@@ -151,7 +151,7 @@ public class WinClient extends AbstractClient {
       println(String
           .format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
               port));
-      handleException(e);
+      handleException();
     }
   }
 
@@ -160,8 +160,7 @@ public class WinClient extends AbstractClient {
       return true;
     }
     String[] cmds = s.trim().split(";");
-    for (int i = 0; i < cmds.length; i++) {
-      String cmd = cmds[i];
+    for (String cmd : cmds) {
       if (cmd != null && !"".equals(cmd.trim())) {
         OperationResult result = handleInputCmd(cmd, connection);
         switch (result) {
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignQueryResultSet.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignQueryResultSet.java
index e71ccb9..8d3cb7d 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignQueryResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBNonAlignQueryResultSet.java
@@ -44,13 +44,13 @@ public class IoTDBNonAlignQueryResultSet extends AbstractIoTDBResultSet {
   private static final int TIMESTAMP_STR_LENGTH = 4;
   private static final String EMPTY_STR = "";
 
-  private TSQueryNonAlignDataSet tsQueryNonAlignDataSet = null;
+  private TSQueryNonAlignDataSet tsQueryNonAlignDataSet;
   private byte[][] times; // used for disable align
 
   // for disable align clause
-  public IoTDBNonAlignQueryResultSet(Statement statement, List<String> columnNameList,
-                                     List<String> columnTypeList, boolean ignoreTimeStamp, TSIService.Iface client,
-                                     String sql, long queryId, long sessionId, TSQueryNonAlignDataSet dataset)
+  IoTDBNonAlignQueryResultSet(Statement statement, List<String> columnNameList,
+      List<String> columnTypeList, boolean ignoreTimeStamp, TSIService.Iface client,
+      String sql, long queryId, long sessionId, TSQueryNonAlignDataSet dataset)
           throws SQLException {
     super(statement, columnNameList, columnTypeList, ignoreTimeStamp, client, sql, queryId, sessionId);