Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
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;
Expand Down Expand Up @@ -253,7 +251,7 @@ private boolean executeSQL(String sql) throws TException, SQLException {
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;
Expand Down Expand Up @@ -350,7 +348,7 @@ private ResultSet executeQuerySQL(String sql) throws TException, SQLException {
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;
Expand Down Expand Up @@ -566,31 +564,6 @@ private void reInit() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,23 @@ public void testQuery() throws Exception {
columns.add("root.vehicle.d0.s0");
columns.add("root.vehicle.d0.s2");

List<String> dataTypeList = new ArrayList<>();
// //BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT
// dataTypeList.add(TSDataType.INT64.toString());
dataTypeList.add("FLOAT");
dataTypeList.add("INT64");
dataTypeList.add("INT32");
dataTypeList.add("FLOAT");

when(execResp.getColumns()).thenReturn(columns);
when(execResp.getDataTypeList()).thenReturn(dataTypeList);
when(execResp.getOperationType()).thenReturn("QUERY");
doReturn("FLOAT").doReturn("INT64").doReturn("INT32").doReturn("FLOAT").when(fetchMetadataResp)
.getDataType();

boolean hasResultSet = statement.execute(testSql);

verify(fetchMetadataResp, times(4)).getDataType();
verify(fetchMetadataResp, times(0)).getDataType();

/*
* step 2: fetch result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,12 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) {
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;
Expand All @@ -567,6 +566,14 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) {
}
}

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);
Expand Down Expand Up @@ -600,8 +607,7 @@ private TSExecuteStatementResp executeAuthQuery(PhysicalPlan plan, List<String>

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()) {
Expand Down
2 changes: 2 additions & 0 deletions service-rpc/src/main/thrift/rpc.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ 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 {
Expand Down