You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2020/03/03 12:10:38 UTC
[incubator-iotdb] 01/01: fix cache non align resultSet
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch fix_disable_align_bug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit b70ab9e6d88128df2306df4ac65385db2453726f
Author: HTHou <hh...@outlook.com>
AuthorDate: Tue Mar 3 20:10:08 2020 +0800
fix cache non align resultSet
---
.../org/apache/iotdb/client/AbstractClient.java | 72 ++++++++++++++++++++--
1 file changed, 68 insertions(+), 4 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 fc77ade..7a09842 100644
--- a/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
+++ b/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
@@ -531,8 +531,15 @@ public abstract class AbstractClient {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnLength = resultSetMetaData.getColumnCount();
List<Integer> maxSizeList = new ArrayList<>(columnLength);
- List<List<String>> lists = cacheResult(resultSet, maxSizeList, columnLength,
- resultSetMetaData, zoneId);
+ List<List<String>> lists;
+ if (resultSet instanceof IoTDBQueryResultSet) {
+ lists = cacheResult(resultSet, maxSizeList, columnLength,
+ resultSetMetaData, zoneId);
+ }
+ else {
+ lists = cacheNonAlignResult(resultSet, maxSizeList, columnLength,
+ resultSetMetaData, zoneId);
+ }
output(lists, maxSizeList);
long costTime = System.currentTimeMillis() - startTime;
println(String.format("It costs %.3fs", costTime / 1000.0));
@@ -544,8 +551,14 @@ public abstract class AbstractClient {
try {
if (br.readLine().equals("")) {
maxSizeList = new ArrayList<>(columnLength);
- lists = cacheResult(resultSet, maxSizeList, columnLength,
- resultSetMetaData, zoneId);
+ if (resultSet instanceof IoTDBQueryResultSet) {
+ lists = cacheResult(resultSet, maxSizeList, columnLength,
+ resultSetMetaData, zoneId);
+ }
+ else {
+ lists = cacheNonAlignResult(resultSet, maxSizeList, columnLength,
+ resultSetMetaData, zoneId);
+ }
output(lists, maxSizeList);
} else {
break;
@@ -611,6 +624,57 @@ public abstract class AbstractClient {
return lists;
}
+ /**
+ * cache all disable align results
+ *
+ * @param resultSet jdbc resultSet
+ * @param maxSizeList the longest result of every column
+ * @param columnCount the number of column
+ * @param resultSetMetaData jdbc resultSetMetaData
+ * @param zoneId your time zone
+ * @return List<List < String>> result
+ * @throws SQLException throw exception
+ */
+ private static List<List<String>> cacheNonAlignResult(ResultSet resultSet, List<Integer> maxSizeList,
+ int columnCount, ResultSetMetaData resultSetMetaData, ZoneId zoneId) throws SQLException {
+
+ List<List<String>> lists = new ArrayList<>(columnCount);
+ for (int i = 1; i <= columnCount; i++) {
+ List<String> list = new ArrayList<>(maxPrintRowCount + 1);
+ if (resultSetMetaData.getColumnLabel(i).startsWith(TIMESTAMP_STR)) {
+ list.add(TIMESTAMP_STR);
+ maxSizeList.add(TIMESTAMP_STR.length());
+ } else {
+ list.add(resultSetMetaData.getColumnLabel(i));
+ maxSizeList.add(resultSetMetaData.getColumnLabel(i).length());
+ }
+ lists.add(list);
+ }
+ int j = 0;
+ if (cursorBeforeFirst) {
+ isReachEnd = !resultSet.next();
+ cursorBeforeFirst = false;
+ }
+ while (j < maxPrintRowCount && !isReachEnd) {
+ for (int i = 1; i <= columnCount; i++) {
+ String tmp = resultSet.getString(i);
+ if (tmp == null) {
+ tmp = NULL;
+ }
+ else if ((i & 1) == 1) { // for Time columns
+ tmp = formatDatetime(resultSet.getLong(i), zoneId);
+ }
+ lists.get(i - 1).add(tmp);
+ if (maxSizeList.get(i - 1) < tmp.length()) {
+ maxSizeList.set(i - 1, tmp.length());
+ }
+ }
+ j++;
+ isReachEnd = !resultSet.next();
+ }
+ return lists;
+ }
+
private static void output(List<List<String>> lists, List<Integer> maxSizeList) {
printBlockLine(maxSizeList);
printRow(lists, 0, maxSizeList);