You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by su...@apache.org on 2019/07/23 11:39:41 UTC
[incubator-iotdb] 01/01: return data type in TSExecuteStatementResp
This is an automated email from the ASF dual-hosted git repository.
suyue pushed a commit to branch remove_fetch_datatype_in_query
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 38df76de97d3bf36a76b4f8e189936655273a227
Author: suyue <23...@qq.com>
AuthorDate: Tue Jul 23 19:39:13 2019 +0800
return data type in TSExecuteStatementResp
---
.../org/apache/iotdb/db/service/TSServiceImpl.java | 20 +++++++++-----
.../java/org/apache/iotdb/jdbc/IoTDBStatement.java | 31 ++--------------------
service-rpc/src/main/thrift/rpc.thrift | 3 +++
3 files changed, 18 insertions(+), 36 deletions(-)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 4aa0a9e..1c8b14a 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -549,13 +549,12 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
resp = executeAuthQuery(plan, columns);
}
+ resp.setColumns(columns);
+ resp.setDataTypeList(queryColumnsType(columns));
resp.setOperationType(plan.getOperatorType().toString());
TSHandleIdentifier operationId = new TSHandleIdentifier(
- ByteBuffer.wrap(username.get().getBytes()),
- ByteBuffer.wrap("PASS".getBytes()));
- TSOperationHandle operationHandle;
- resp.setColumns(columns);
- operationHandle = new TSOperationHandle(operationId, true);
+ ByteBuffer.wrap(username.get().getBytes()), ByteBuffer.wrap("PASS".getBytes()));
+ TSOperationHandle operationHandle = new TSOperationHandle(operationId, true);
resp.setOperationHandle(operationHandle);
recordANewQuery(statement, plan);
return resp;
@@ -567,6 +566,14 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
}
}
+ private List<String> queryColumnsType(List<String> columns) throws PathErrorException {
+ List<String> columnTypes = new ArrayList<>();
+ for (String column : columns) {
+ columnTypes.add(getSeriesType(column).toString());
+ }
+ return columnTypes;
+ }
+
private TSExecuteStatementResp executeAuthQuery(PhysicalPlan plan, List<String> columns) {
TSExecuteStatementResp resp = getTSExecuteStatementResp(TS_StatusCode.SUCCESS_STATUS, "");
resp.setIgnoreTimeStamp(true);
@@ -600,8 +607,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
private TSExecuteStatementResp executeDataQuery(PhysicalPlan plan, List<String> columns)
throws AuthException, TException {
- List<Path> paths;
- paths = plan.getPaths();
+ List<Path> paths = plan.getPaths();
// check seriesPath exists
if (paths.isEmpty()) {
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
index ade9f51..704bc5f 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
@@ -38,8 +38,6 @@ import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementReq;
import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp;
import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq;
import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp;
-import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq;
-import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp;
import org.apache.iotdb.service.rpc.thrift.TSIService;
import org.apache.iotdb.service.rpc.thrift.TSOperationHandle;
import org.apache.iotdb.service.rpc.thrift.TS_SessionHandle;
@@ -253,7 +251,7 @@ public class IoTDBStatement implements Statement {
IoTDBQueryResultSet resSet = new IoTDBQueryResultSet(this,
execResp.getColumns(), client,
operationHandle, sql, execResp.getOperationType(),
- getColumnsType(execResp.getColumns()), queryId.getAndIncrement());
+ execResp.getDataTypeList(), queryId.getAndIncrement());
resSet.setIgnoreTimeStamp(execResp.ignoreTimeStamp);
this.resultSet = resSet;
return true;
@@ -350,7 +348,7 @@ public class IoTDBStatement implements Statement {
operationHandle = execResp.getOperationHandle();
Utils.verifySuccess(execResp.getStatus());
IoTDBQueryResultSet resSet = new IoTDBQueryResultSet(this, execResp.getColumns(), client,
- operationHandle, sql, execResp.getOperationType(), getColumnsType(execResp.getColumns()),
+ operationHandle, sql, execResp.getOperationType(), execResp.getDataTypeList(),
queryId.getAndIncrement());
resSet.setIgnoreTimeStamp(execResp.ignoreTimeStamp);
this.resultSet = resSet;
@@ -566,31 +564,6 @@ public class IoTDBStatement implements Statement {
this.sessionHandle = connection.sessionHandle;
}
- private List<String> getColumnsType(List<String> columns) throws SQLException {
- List<String> columnTypes = new ArrayList<>();
- for (String column : columns) {
- columnTypes.add(getColumnType(column));
- }
- return columnTypes;
- }
-
- private String getColumnType(String columnName) throws SQLException {
- TSFetchMetadataReq req;
-
- req = new TSFetchMetadataReq(Constant.GLOBAL_COLUMN_REQ);
- req.setColumnPath(columnName);
-
- TSFetchMetadataResp resp;
- try {
- resp = client.fetchMetadata(req);
- Utils.verifySuccess(resp.getStatus());
- return resp.getDataType();
- } catch (TException | IoTDBSQLException e) {
- throw new SQLException(
- String.format("Cannot get column %s data type", columnName), e);
- }
- }
-
void requestStmtId() throws SQLException {
try {
this.stmtId = client.requestStatementId();
diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift
index e64c659..6511e4e 100644
--- a/service-rpc/src/main/thrift/rpc.thrift
+++ b/service-rpc/src/main/thrift/rpc.thrift
@@ -74,6 +74,9 @@ struct TSExecuteStatementResp {
3: optional list<string> columns
4: optional string operationType
5: optional bool ignoreTimeStamp
+
+ // Data type list of columns in select statement of SQL
+ 6: optional list<string> dataTypeList
}
enum TSProtocolVersion {