This is an automated email from the ASF dual-hosted git repository.
rong 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 f28f1fd3787 JDBC: Support different charsets (#12632)
f28f1fd3787 is described below
commit f28f1fd378768ba37b7a870f5c0f1513b23ca578
Author: Steve Yurong Su <[email protected]>
AuthorDate: Fri May 31 23:07:03 2024 +0800
JDBC: Support different charsets (#12632)
---
.../java/org/apache/iotdb/JDBCCharsetExample.java | 99 ++++++++++++++++++++++
.../main/java/org/apache/iotdb/jdbc/Config.java | 3 +
.../org/apache/iotdb/jdbc/IoTDBConnection.java | 10 ++-
.../apache/iotdb/jdbc/IoTDBConnectionParams.java | 12 +++
.../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java | 60 ++++++++++++-
.../apache/iotdb/jdbc/IoTDBPreparedStatement.java | 16 +++-
.../java/org/apache/iotdb/jdbc/IoTDBStatement.java | 91 ++++++++++++++++----
.../src/main/java/org/apache/iotdb/jdbc/Utils.java | 16 +++-
.../org/apache/iotdb/jdbc/IoTDBStatementTest.java | 8 +-
.../java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java | 8 ++
10 files changed, 294 insertions(+), 29 deletions(-)
diff --git
a/example/jdbc/src/main/java/org/apache/iotdb/JDBCCharsetExample.java
b/example/jdbc/src/main/java/org/apache/iotdb/JDBCCharsetExample.java
new file mode 100644
index 00000000000..79ae881e301
--- /dev/null
+++ b/example/jdbc/src/main/java/org/apache/iotdb/JDBCCharsetExample.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb;
+
+import org.apache.iotdb.jdbc.IoTDBSQLException;
+import org.apache.iotdb.jdbc.IoTDBStatement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public class JDBCCharsetExample {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(JDBCCharsetExample.class);
+
+ public static void main(String[] args) throws Exception {
+ Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
+
+ try (final Connection connection =
+ DriverManager.getConnection(
+ "jdbc:iotdb://127.0.0.1:6667?charset=GB18030", "root", "root");
+ final IoTDBStatement statement = (IoTDBStatement)
connection.createStatement()) {
+
+ final String insertSQLWithGB18030 =
+ "insert into root.测试(timestamp, 维语, 彝语, 繁体, 蒙文, 简体, 标点符号, 藏语)
values(1, 'ئۇيغۇر تىلى', 'ꆈꌠꉙ', \"繁體\", 'ᠮᠣᠩᠭᠣᠯ ᠬᠡᠯᠡ', '简体', '——?!',
\"བོད་སྐད།\");";
+ final byte[] insertSQLWithGB18030Bytes =
insertSQLWithGB18030.getBytes("GB18030");
+ statement.execute(insertSQLWithGB18030Bytes);
+ } catch (IoTDBSQLException e) {
+ LOGGER.error("IoTDB Jdbc example error", e);
+ }
+
+ outputResult("GB18030");
+ outputResult("UTF-8");
+ outputResult("UTF-16");
+ outputResult("GBK");
+ outputResult("ISO-8859-1");
+ }
+
+ private static void outputResult(String charset) throws SQLException {
+ System.out.println("[Charset: " + charset + "]");
+ try (final Connection connection =
+ DriverManager.getConnection(
+ "jdbc:iotdb://127.0.0.1:6667?charset=" + charset, "root",
"root");
+ final IoTDBStatement statement = (IoTDBStatement)
connection.createStatement()) {
+ outputResult(statement.executeQuery("select ** from root"),
Charset.forName(charset));
+ } catch (IoTDBSQLException e) {
+ LOGGER.error("IoTDB Jdbc example error", e);
+ }
+ }
+
+ private static void outputResult(ResultSet resultSet, Charset charset)
throws SQLException {
+ if (resultSet != null) {
+ System.out.println("--------------------------");
+ final ResultSetMetaData metaData = resultSet.getMetaData();
+ final int columnCount = metaData.getColumnCount();
+ for (int i = 0; i < columnCount; i++) {
+ System.out.print(metaData.getColumnLabel(i + 1) + " ");
+ }
+ System.out.println();
+
+ while (resultSet.next()) {
+ for (int i = 1; ; i++) {
+ System.out.print(
+ resultSet.getString(i) + " (" + new
String(resultSet.getBytes(i), charset) + ")");
+ if (i < columnCount) {
+ System.out.print(", ");
+ } else {
+ System.out.println();
+ break;
+ }
+ }
+ }
+ System.out.println("--------------------------\n");
+ }
+ }
+}
diff --git a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
index 407f07ef30d..4e2e0f38300 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
@@ -73,6 +73,9 @@ public class Config {
/** Key of connection's time zone. */
public static final String TIME_ZONE = "time_zone";
+ /** Key of connection's charset. */
+ public static final String CHARSET = "charset";
+
public static final String USE_SSL = "use_ssl";
public static final String TRUST_STORE = "trust_store";
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index 8b3bef19cb9..06e92215155 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -39,6 +39,7 @@ import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
@@ -89,6 +90,8 @@ public class IoTDBConnection implements Connection {
private int networkTimeout = Config.DEFAULT_CONNECTION_TIMEOUT_MS;
private ZoneId zoneId;
+ private Charset charset;
+
private boolean autoCommit;
private String url;
@@ -111,6 +114,7 @@ public class IoTDBConnection implements Connection {
this.userName = info.get("user").toString();
this.networkTimeout = params.getNetworkTimeout();
this.zoneId = ZoneId.of(params.getTimeZone());
+ this.charset = params.getCharset();
openTransport();
if (Config.rpcThriftCompressionEnable) {
setClient(new IClientRPCService.Client(new TCompactProtocol(transport)));
@@ -200,7 +204,7 @@ public class IoTDBConnection implements Connection {
if (isClosed) {
throw new SQLException("Cannot create statement because connection is
closed");
}
- return new IoTDBStatement(this, getClient(), sessionId, zoneId,
queryTimeout);
+ return new IoTDBStatement(this, getClient(), sessionId, zoneId, charset,
queryTimeout);
}
@Override
@@ -215,7 +219,7 @@ public class IoTDBConnection implements Connection {
throw new SQLException(
String.format("Statements with ResultSet type %d are not supported",
resultSetType));
}
- return new IoTDBStatement(this, getClient(), sessionId, zoneId,
queryTimeout);
+ return new IoTDBStatement(this, getClient(), sessionId, zoneId, charset,
queryTimeout);
}
@Override
@@ -366,7 +370,7 @@ public class IoTDBConnection implements Connection {
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
- return new IoTDBPreparedStatement(this, getClient(), sessionId, sql,
zoneId);
+ return new IoTDBPreparedStatement(this, getClient(), sessionId, sql,
zoneId, charset);
}
@Override
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnectionParams.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnectionParams.java
index d1523691f79..07700bad2b1 100644
---
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnectionParams.java
+++
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnectionParams.java
@@ -21,6 +21,9 @@ package org.apache.iotdb.jdbc;
import org.apache.iotdb.rpc.RpcUtils;
+import org.apache.tsfile.common.conf.TSFileConfig;
+
+import java.nio.charset.Charset;
import java.time.ZoneId;
public class IoTDBConnectionParams {
@@ -40,6 +43,7 @@ public class IoTDBConnectionParams {
private int networkTimeout = Config.DEFAULT_CONNECTION_TIMEOUT_MS;
private String timeZone = ZoneId.systemDefault().toString();
+ private Charset charset = TSFileConfig.STRING_CHARSET;
private boolean useSSL = false;
private String trustStore;
@@ -141,6 +145,14 @@ public class IoTDBConnectionParams {
return this.timeZone;
}
+ public void setCharset(String charsetName) {
+ this.charset = Charset.forName(charsetName);
+ }
+
+ public Charset getCharset() {
+ return charset;
+ }
+
public boolean isUseSSL() {
return useSSL;
}
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 df558b18809..60fa9c98373 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
@@ -27,6 +27,8 @@ import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
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.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,6 +39,7 @@ import java.math.BigDecimal;
import java.math.MathContext;
import java.net.URL;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -70,6 +73,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
private String operationType = "";
private List<String> columns = null;
private List<String> sgColumns = null;
+ private Charset charset = TSFileConfig.STRING_CHARSET;
private String timeFormat = RpcUtils.DEFAULT_TIME_FORMAT;
@SuppressWarnings("squid:S107") // ignore Methods should not have too many
parameters
@@ -91,7 +95,8 @@ public class IoTDBJDBCResultSet implements ResultSet {
List<String> sgColumns,
BitSet aliasColumnMap,
boolean moreData,
- ZoneId zoneId)
+ ZoneId zoneId,
+ Charset charset)
throws SQLException {
this.ioTDBRpcDataSet =
new IoTDBRpcDataSet(
@@ -121,6 +126,51 @@ public class IoTDBJDBCResultSet implements ResultSet {
this.operationType = operationType;
this.columns = columns;
this.sgColumns = sgColumns;
+ this.charset = charset;
+ }
+
+ @SuppressWarnings("squid:S107") // ignore Methods should not have too many
parameters
+ public IoTDBJDBCResultSet(
+ Statement statement,
+ List<String> columnNameList,
+ List<String> columnTypeList,
+ Map<String, Integer> columnNameIndex,
+ boolean ignoreTimeStamp,
+ IClientRPCService.Iface client,
+ String sql,
+ long queryId,
+ long sessionId,
+ List<ByteBuffer> dataSet,
+ TSTracingInfo tracingInfo,
+ long timeout,
+ boolean moreData,
+ ZoneId zoneId,
+ Charset charset)
+ throws SQLException {
+ this.ioTDBRpcDataSet =
+ new IoTDBRpcDataSet(
+ sql,
+ columnNameList,
+ columnTypeList,
+ columnNameIndex,
+ ignoreTimeStamp,
+ moreData,
+ queryId,
+ ((IoTDBStatement) statement).getStmtId(),
+ client,
+ sessionId,
+ dataSet,
+ statement.getFetchSize(),
+ timeout,
+ zoneId,
+ timeFormat);
+ this.statement = statement;
+ this.columnTypeList = columnTypeList;
+ if (tracingInfo != null) {
+ ioTDBRpcTracingInfo = new IoTDBTracingInfo();
+ ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
+ }
+ this.charset = charset;
}
@SuppressWarnings("squid:S107") // ignore Methods should not have too many
parameters
@@ -327,7 +377,9 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public byte[] getBytes(int columnIndex) throws SQLException {
try {
- return ioTDBRpcDataSet.getBinary(columnIndex).getValues();
+ return ioTDBRpcDataSet.getDataType(columnIndex).equals(TSDataType.BLOB)
+ ? ioTDBRpcDataSet.getBinary(columnIndex).getValues()
+ : ioTDBRpcDataSet.getString(columnIndex).getBytes(charset);
} catch (StatementExecutionException e) {
throw new SQLException(e.getMessage());
}
@@ -336,7 +388,9 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public byte[] getBytes(String columnName) throws SQLException {
try {
- return ioTDBRpcDataSet.getBinary(columnName).getValues();
+ return ioTDBRpcDataSet.getDataType(columnName).equals(TSDataType.BLOB)
+ ? ioTDBRpcDataSet.getBinary(columnName).getValues()
+ : ioTDBRpcDataSet.getString(columnName).getBytes(charset);
} catch (StatementExecutionException e) {
throw new SQLException(e.getMessage());
}
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
index 6cc0db318de..72e5c8b0818 100644
---
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
+++
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
@@ -32,6 +32,7 @@ import java.io.Reader;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URL;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -71,10 +72,23 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
/** save the SQL parameters as (paramLoc,paramValue) pairs. */
private final Map<Integer, String> parameters = new HashMap<>();
+ IoTDBPreparedStatement(
+ IoTDBConnection connection,
+ Iface client,
+ Long sessionId,
+ String sql,
+ ZoneId zoneId,
+ Charset charset)
+ throws SQLException {
+ super(connection, client, sessionId, zoneId, charset);
+ this.sql = sql;
+ }
+
+ // Only for tests
IoTDBPreparedStatement(
IoTDBConnection connection, Iface client, Long sessionId, String sql,
ZoneId zoneId)
throws SQLException {
- super(connection, client, sessionId, zoneId);
+ super(connection, client, sessionId, zoneId, TSFileConfig.STRING_CHARSET);
this.sql = sql;
}
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
index 6d93c932d0d..eaa080aaefe 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
@@ -31,7 +31,9 @@ import
org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq;
import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp;
import org.apache.thrift.TException;
+import org.apache.tsfile.common.conf.TSFileConfig;
+import java.nio.charset.Charset;
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -45,12 +47,15 @@ import java.util.List;
public class IoTDBStatement implements Statement {
- ZoneId zoneId;
+ private final IoTDBConnection connection;
+
private ResultSet resultSet = null;
- private IoTDBConnection connection;
private int fetchSize;
private int maxRows = 0;
+ protected final ZoneId zoneId;
+ protected final Charset charset;
+
/**
* Timeout of query can be set by users. Unit: s. A negative number means
using the default
* configuration of server. And value 0 will disable the function of query
timeout.
@@ -82,6 +87,7 @@ public class IoTDBStatement implements Statement {
long sessionId,
int fetchSize,
ZoneId zoneId,
+ Charset charset,
int seconds)
throws SQLException {
this.connection = connection;
@@ -90,11 +96,51 @@ public class IoTDBStatement implements Statement {
this.fetchSize = fetchSize;
this.batchSQLList = new ArrayList<>();
this.zoneId = zoneId;
+ this.charset = charset;
this.queryTimeout = seconds;
requestStmtId();
}
- // only for test
+ IoTDBStatement(
+ IoTDBConnection connection,
+ IClientRPCService.Iface client,
+ long sessionId,
+ ZoneId zoneId,
+ Charset charset,
+ int seconds)
+ throws SQLException {
+ this(connection, client, sessionId, Config.DEFAULT_FETCH_SIZE, zoneId,
charset, seconds);
+ }
+
+ IoTDBStatement(
+ IoTDBConnection connection,
+ IClientRPCService.Iface client,
+ long sessionId,
+ ZoneId zoneId,
+ Charset charset)
+ throws SQLException {
+ this(connection, client, sessionId, Config.DEFAULT_FETCH_SIZE, zoneId,
charset, 0);
+ }
+
+ // Only for tests
+ IoTDBStatement(
+ IoTDBConnection connection,
+ IClientRPCService.Iface client,
+ long sessionId,
+ ZoneId zoneId,
+ int seconds)
+ throws SQLException {
+ this(
+ connection,
+ client,
+ sessionId,
+ Config.DEFAULT_FETCH_SIZE,
+ zoneId,
+ TSFileConfig.STRING_CHARSET,
+ seconds);
+ }
+
+ // Only for tests
IoTDBStatement(
IoTDBConnection connection,
IClientRPCService.Iface client,
@@ -108,24 +154,23 @@ public class IoTDBStatement implements Statement {
this.fetchSize = Config.DEFAULT_FETCH_SIZE;
this.batchSQLList = new ArrayList<>();
this.zoneId = zoneId;
+ this.charset = TSFileConfig.STRING_CHARSET;
this.queryTimeout = seconds;
this.stmtId = statementId;
}
+ // Only for tests
IoTDBStatement(
IoTDBConnection connection, IClientRPCService.Iface client, long
sessionId, ZoneId zoneId)
throws SQLException {
- this(connection, client, sessionId, Config.DEFAULT_FETCH_SIZE, zoneId, 0);
- }
-
- IoTDBStatement(
- IoTDBConnection connection,
- IClientRPCService.Iface client,
- long sessionId,
- ZoneId zoneId,
- int seconds)
- throws SQLException {
- this(connection, client, sessionId, Config.DEFAULT_FETCH_SIZE, zoneId,
seconds);
+ this(
+ connection,
+ client,
+ sessionId,
+ Config.DEFAULT_FETCH_SIZE,
+ zoneId,
+ TSFileConfig.STRING_CHARSET,
+ 0);
}
@Override
@@ -206,6 +251,18 @@ public class IoTDBStatement implements Statement {
throw new SQLException("Not support closeOnCompletion");
}
+ /**
+ * Execute a SQL encoded in bytes with {@link IoTDBStatement#charset}.
+ *
+ * @param sql raw sql in bytes encoded with {@link IoTDBStatement#charset}
+ * @return true if the first result is a {@link ResultSet} object; false if
the first result is an
+ * update count or there is no result
+ * @throws SQLException if a database access error occurs
+ */
+ public boolean execute(byte[] sql) throws SQLException {
+ return execute(new String(sql, charset));
+ }
+
@Override
public boolean execute(String sql) throws SQLException {
checkConnection("execute");
@@ -302,7 +359,8 @@ public class IoTDBStatement implements Statement {
execResp.tracingInfo,
execReq.timeout,
execResp.moreData,
- zoneId);
+ zoneId,
+ charset);
}
return true;
}
@@ -457,7 +515,8 @@ public class IoTDBStatement implements Statement {
execResp.sgColumns,
aliasColumn,
execResp.moreData,
- zoneId);
+ zoneId,
+ charset);
}
return resultSet;
}
diff --git a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
index af884d3e781..dcda9e3071e 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.jdbc;
+import java.nio.charset.Charset;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.util.Properties;
@@ -104,19 +105,18 @@ public class Utils {
if (info.containsKey(Config.TIME_ZONE)) {
params.setTimeZone(info.getProperty(Config.TIME_ZONE));
}
-
+ if (info.containsKey(Config.CHARSET)) {
+ params.setCharset(info.getProperty(Config.CHARSET));
+ }
if (info.containsKey(Config.USE_SSL)) {
params.setUseSSL(Boolean.parseBoolean(info.getProperty(Config.USE_SSL)));
}
-
if (info.containsKey(Config.TRUST_STORE)) {
params.setTrustStore(info.getProperty(Config.TRUST_STORE));
}
-
if (info.containsKey(Config.TRUST_STORE_PWD)) {
params.setTrustStorePwd(info.getProperty(Config.TRUST_STORE_PWD));
}
-
return params;
}
@@ -165,6 +165,14 @@ public class Utils {
}
info.put(key, value);
break;
+ case Config.CHARSET:
+ try {
+ Charset.forName(value);
+ } catch (Exception e) {
+ return false;
+ }
+ info.put(key, value);
+ break;
default:
return false;
}
diff --git
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
index 2699c442d39..5cfd5342e05 100644
---
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
+++
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
@@ -24,6 +24,7 @@ import
org.apache.iotdb.service.rpc.thrift.IClientRPCService.Iface;
import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq;
import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp;
+import org.apache.tsfile.common.conf.TSFileConfig;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -84,7 +85,9 @@ public class IoTDBStatementTest {
@Test
public void testSetFetchSize3() throws SQLException {
final int fetchSize = 10000;
- IoTDBStatement stmt = new IoTDBStatement(connection, client, sessionId,
fetchSize, zoneID, 0);
+ IoTDBStatement stmt =
+ new IoTDBStatement(
+ connection, client, sessionId, fetchSize, zoneID,
TSFileConfig.STRING_CHARSET, 0);
assertEquals(fetchSize, stmt.getFetchSize());
}
@@ -97,7 +100,8 @@ public class IoTDBStatementTest {
@Test
public void setTimeoutTest() throws SQLException {
- IoTDBStatement statement = new IoTDBStatement(connection, client,
sessionId, zoneID, 60);
+ IoTDBStatement statement =
+ new IoTDBStatement(connection, client, sessionId, zoneID,
TSFileConfig.STRING_CHARSET, 60);
Assert.assertEquals(60, statement.getQueryTimeout());
statement.setQueryTimeout(100);
Assert.assertEquals(100, statement.getQueryTimeout());
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 d901f36f01f..c32e310b65f 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
@@ -523,6 +523,14 @@ public class IoTDBRpcDataSet {
return getTimestamp(findColumn(columnName));
}
+ public TSDataType getDataType(int columnIndex) throws
StatementExecutionException {
+ return getDataType(findColumnNameByIndex(columnIndex));
+ }
+
+ public TSDataType getDataType(String columnName) throws
StatementExecutionException {
+ return columnTypeDeduplicatedList.get(columnOrdinalMap.get(columnName) -
START_INDEX);
+ }
+
public int findColumn(String columnName) {
return columnOrdinalMap.get(columnName);
}