in backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java [2116:2166]
private DataVO getDataBySql(String sql, SessionPool sessionPool) throws BaseException {
SessionDataSetWrapper sessionDataSetWrapper = null;
DataVO dataVO = new DataVO();
List<List<String>> valueList = new ArrayList<>();
try {
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
List<String> columnTypes = sessionDataSetWrapper.getColumnTypes();
dataVO.setTypeList(columnTypes);
List<String> columnNames = sessionDataSetWrapper.getColumnNames();
dataVO.setMetaDataList(columnNames);
if ("Time".equals(columnNames.get(0))) {
while (sessionDataSetWrapper.hasNext()) {
List<String> lineValueList = new ArrayList<>();
RowRecord rowRecord = sessionDataSetWrapper.next();
long timestamp = rowRecord.getTimestamp();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
Date date = new Date(timestamp);
String timeStr = simpleDateFormat.format(date);
lineValueList.add(timeStr);
for (org.apache.iotdb.tsfile.read.common.Field field : rowRecord.getFields()) {
lineValueList.add(field.toString());
}
valueList.add(lineValueList);
}
} else {
while (sessionDataSetWrapper.hasNext()) {
List<String> lineValueList = new ArrayList<>();
RowRecord rowRecord = sessionDataSetWrapper.next();
for (org.apache.iotdb.tsfile.read.common.Field field : rowRecord.getFields()) {
lineValueList.add(field.toString());
}
valueList.add(lineValueList);
}
}
dataVO.setValueList(valueList);
return dataVO;
} catch (IoTDBConnectionException e) {
logger.error(e.getMessage());
throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG);
} catch (StatementExecutionException e) {
logger.error(e.getMessage());
if (e.getStatusCode() == 602) {
throw new BaseException(
ErrorCode.NO_PRI_TIMESERIES_DATA, ErrorCode.NO_PRI_TIMESERIES_DATA_MSG);
} else {
throw new BaseException(ErrorCode.GET_DATA_FAIL, ErrorCode.GET_DATA_FAIL_MSG);
}
} finally {
closeResultSet(sessionDataSetWrapper);
}
}