This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 28c970b1107 [IOTDB-6344] Display null in cli
28c970b1107 is described below
commit 28c970b1107c3400679b22f48ca70b93a9d792e0
Author: Jackie Tien <[email protected]>
AuthorDate: Wed Jun 26 19:54:46 2024 +0800
[IOTDB-6344] Display null in cli
---
.../apache/iotdb/cli/it/StartClientScriptIT.java | 65 ++++++++++++++++++++++
.../java/org/apache/iotdb/cli/AbstractCli.java | 27 ++++++---
.../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java | 23 ++++++--
3 files changed, 100 insertions(+), 15 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
b/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
index 7f9a2328929..317ec218fc6 100644
---
a/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
@@ -151,5 +151,70 @@ public class StartClientScriptIT extends AbstractScript {
"\"flush\"");
builder2.environment().put("IOTDB_HOME", homePath);
testOutput(builder2, output2, 0);
+
+ // test null display
+ final String[] successfulDisplay = {"Msg: The statement is executed
successfully."};
+ ProcessBuilder builder3 =
+ new ProcessBuilder(
+ "bash",
+ sbinPath + File.separator + "start-cli.sh",
+ "-h",
+ ip,
+ "-p",
+ port,
+ "-e",
+ "\"CREATE ALIGNED TIMESERIES root.db.d1(s_boolean BOOLEAN, s_int32
INT32)\"");
+ builder3.environment().put("IOTDB_HOME", homePath);
+ testOutput(builder3, successfulDisplay, 0);
+
+ ProcessBuilder builder4 =
+ new ProcessBuilder(
+ "bash",
+ sbinPath + File.separator + "start-cli.sh",
+ "-h",
+ ip,
+ "-p",
+ port,
+ "-e",
+ "\"insert into root.db.d1(time, s_int32) values(0,0)\"");
+ builder4.environment().put("IOTDB_HOME", homePath);
+ testOutput(builder4, successfulDisplay, 0);
+
+ final String[] output5 = {"Time zone has set to asia/shanghai"};
+ ProcessBuilder builder5 =
+ new ProcessBuilder(
+ "bash",
+ sbinPath + File.separator + "start-cli.sh",
+ "-h",
+ ip,
+ "-p",
+ port,
+ "-e",
+ "\"set time_zone=Asia/Shanghai\"");
+ builder5.environment().put("IOTDB_HOME", homePath);
+ testOutput(builder5, output5, 0);
+
+ final String[] output6 = {
+ "+----+------------------+--------------------+",
+ "|Time|root.db.d1.s_int32|root.db.d1.s_boolean|",
+ "+----+------------------+--------------------+",
+ "| 0| 0| null|",
+ "+----+------------------+--------------------+",
+ "Total line number = 1",
+ "It costs "
+ };
+ ProcessBuilder builder6 =
+ new ProcessBuilder(
+ "bash",
+ sbinPath + File.separator + "start-cli.sh",
+ "-h",
+ ip,
+ "-p",
+ port,
+ "-disableISO8601",
+ "-e",
+ "\"select s_int32, s_boolean from root.db.d1\"");
+ builder6.environment().put("IOTDB_HOME", homePath);
+ testOutput(builder6, output6, 0);
}
}
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());
}