You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2024/06/05 04:40:53 UTC

(iotdb) branch fix-jdbc-getbytes created (now 400a60869b8)

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

rong pushed a change to branch fix-jdbc-getbytes
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 400a60869b8 JDBC: Fix ArrayOutOfBoundException when calling getBytes

This branch includes the following new commits:

     new 400a60869b8 JDBC: Fix ArrayOutOfBoundException when calling getBytes

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: JDBC: Fix ArrayOutOfBoundException when calling getBytes

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

rong pushed a commit to branch fix-jdbc-getbytes
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 400a60869b84c60e64920b632584d2fe7fbf26bc
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed Jun 5 12:40:46 2024 +0800

    JDBC: Fix ArrayOutOfBoundException when calling getBytes
---
 .../main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java  | 12 ++++++++++--
 .../src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java  |  8 +++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

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 60fa9c98373..ab6009343aa 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
@@ -377,7 +377,11 @@ public class IoTDBJDBCResultSet implements ResultSet {
   @Override
   public byte[] getBytes(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getDataType(columnIndex).equals(TSDataType.BLOB)
+      final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnIndex);
+      if (dataType == null) {
+        return null;
+      }
+      return dataType.equals(TSDataType.BLOB)
           ? ioTDBRpcDataSet.getBinary(columnIndex).getValues()
           : ioTDBRpcDataSet.getString(columnIndex).getBytes(charset);
     } catch (StatementExecutionException e) {
@@ -388,7 +392,11 @@ public class IoTDBJDBCResultSet implements ResultSet {
   @Override
   public byte[] getBytes(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getDataType(columnName).equals(TSDataType.BLOB)
+      final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnName);
+      if (dataType == null) {
+        return null;
+      }
+      return dataType.equals(TSDataType.BLOB)
           ? ioTDBRpcDataSet.getBinary(columnName).getValues()
           : ioTDBRpcDataSet.getString(columnName).getBytes(charset);
     } catch (StatementExecutionException e) {
diff --git a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
index c32e310b65f..014c5eedae1 100644
--- a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
+++ b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
@@ -528,7 +528,13 @@ public class IoTDBRpcDataSet {
   }
 
   public TSDataType getDataType(String columnName) throws StatementExecutionException {
-    return columnTypeDeduplicatedList.get(columnOrdinalMap.get(columnName) - START_INDEX);
+    if (columnName.equals(TIMESTAMP_STR)) {
+      return TSDataType.INT64;
+    }
+    final int index = columnOrdinalMap.get(columnName) - START_INDEX;
+    return index < 0 || index >= columnTypeDeduplicatedList.size()
+        ? null
+        : columnTypeDeduplicatedList.get(index);
   }
 
   public int findColumn(String columnName) {