You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/02/10 10:13:00 UTC
[GitHub] [incubator-iotdb] Genius-pig commented on a change in pull request
#782: [IOTDB-405] cache results in the client and makes the display look
nice.
Genius-pig commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376970344
##########
File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
##########
@@ -805,34 +503,100 @@ private static void importCmd(String specialCmd, String cmd, IoTDBConnection con
} catch (SQLException e) {
println(String.format("Failed to import from %s because %s",
cmd.split(" ")[1], e.getMessage()));
- handleException(e);
} catch (TException e) {
println("Cannot connect to server");
- handleException(e);
}
}
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();
+ try (ResultSet resultSet = statement.getResultSet()) {
+ 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);
}
}
} catch (Exception e) {
println("Msg: " + e.getMessage());
- handleException(e);
}
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()) {
Review comment:
format what?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services