You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2024/06/26 06:42:58 UTC
(iotdb) branch ty/FixCli created (now 496e07b45b9)
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a change to branch ty/FixCli
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at 496e07b45b9 [IOTDB-6344] Display null in cli
This branch includes the following new commits:
new 496e07b45b9 [IOTDB-6344] Display null in cli
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.
(iotdb) 01/01: [IOTDB-6344] Display null in cli
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/FixCli
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 496e07b45b9ff32504f1a9d8ac08bdeaf48ae088
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Wed Jun 26 14:42:29 2024 +0800
[IOTDB-6344] Display null in cli
---
.../java/org/apache/iotdb/cli/AbstractCli.java | 27 ++++++++++++++--------
.../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java | 23 +++++++++++++-----
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
index afc4c23ba88..0da407e00f0 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
@@ -721,25 +721,34 @@ public abstract class AbstractCli {
TSDataType type = TSDataType.valueOf(resultSet.getColumnTypeByIndex(columnIndex));
switch (type) {
case BOOLEAN:
- return String.valueOf(resultSet.getBoolean(columnIndex));
case INT32:
- return String.valueOf(resultSet.getInt(columnIndex));
case INT64:
- return String.valueOf(resultSet.getLong(columnIndex));
case FLOAT:
- return String.valueOf(resultSet.getFloat(columnIndex));
case DOUBLE:
- return String.valueOf(resultSet.getDouble(columnIndex));
case TEXT:
case STRING:
return resultSet.getString(columnIndex);
case BLOB:
- return BytesUtils.parseBlobByteArrayToString(resultSet.getBytes(columnIndex));
+ byte[] v = resultSet.getBytes(columnIndex);
+ if (v == null) {
+ return null;
+ } else {
+ return BytesUtils.parseBlobByteArrayToString(v);
+ }
case DATE:
- return DateUtils.formatDate(resultSet.getInt(columnIndex));
+ int intValue = resultSet.getInt(columnIndex);
+ if (resultSet.wasNull()) {
+ return null;
+ } else {
+ return DateUtils.formatDate(intValue);
+ }
case TIMESTAMP:
- return RpcUtils.formatDatetime(
- timeFormat, timestampPrecision, resultSet.getLong(columnIndex), zoneId);
+ long longValue = resultSet.getLong(columnIndex);
+ if (resultSet.wasNull()) {
+ return null;
+ } else {
+ return RpcUtils.formatDatetime(timeFormat, timestampPrecision, longValue, zoneId);
+ }
default:
return null;
}
diff --git a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
index 269d6ec7c26..e5c0e60e841 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.service.rpc.thrift.TSTracingInfo;
import org.apache.thrift.TException;
import org.apache.tsfile.common.conf.TSFileConfig;
import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -381,9 +382,14 @@ public class IoTDBJDBCResultSet implements ResultSet {
if (dataType == null) {
return null;
}
- return dataType.equals(TSDataType.BLOB)
- ? ioTDBRpcDataSet.getBinary(columnIndex).getValues()
- : ioTDBRpcDataSet.getString(columnIndex).getBytes(charset);
+
+ if (dataType.equals(TSDataType.BLOB)) {
+ Binary binary = ioTDBRpcDataSet.getBinary(columnIndex);
+ return binary == null ? null : binary.getValues();
+ } else {
+ String s = ioTDBRpcDataSet.getString(columnIndex);
+ return s == null ? null : s.getBytes(charset);
+ }
} catch (StatementExecutionException e) {
throw new SQLException(e.getMessage());
}
@@ -396,9 +402,14 @@ public class IoTDBJDBCResultSet implements ResultSet {
if (dataType == null) {
return null;
}
- return dataType.equals(TSDataType.BLOB)
- ? ioTDBRpcDataSet.getBinary(columnName).getValues()
- : ioTDBRpcDataSet.getString(columnName).getBytes(charset);
+
+ if (dataType.equals(TSDataType.BLOB)) {
+ Binary binary = ioTDBRpcDataSet.getBinary(columnName);
+ return binary == null ? null : binary.getValues();
+ } else {
+ String s = ioTDBRpcDataSet.getString(columnName);
+ return s == null ? null : s.getBytes(charset);
+ }
} catch (StatementExecutionException e) {
throw new SQLException(e.getMessage());
}