in backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java [98:145]
public DataCountVO getDataCount(Connection connection) throws BaseException {
SessionPool sessionPool = null;
try {
sessionPool = getSessionPool(connection);
String iotdbVersion = executeQueryOneValue(sessionPool, "show version");
logger.info("执行成功,获得iotdb版本号:" + iotdbVersion);
int versionFlag = 0;
if (iotdbVersion.contains("0.12.")) {
versionFlag = 12;
} else if (iotdbVersion.contains("0.13.") || iotdbVersion.contains("0.14.")) {
versionFlag = 13;
}
String groupCountStr = executeQueryOneValue(sessionPool, "count storage group");
int groupCount = Integer.parseInt(groupCountStr);
String deviceCountStr = executeQueryOneValue(sessionPool, "count devices");
int deviceCount = Integer.parseInt(deviceCountStr);
String measurementCountStr = executeQueryOneValue(sessionPool, "count timeseries");
int measurementCount = Integer.parseInt(measurementCountStr);
List<String> dataCountList = new ArrayList<>();
if (versionFlag == 13) {
dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root.**");
} else if (versionFlag == 12) {
try {
dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root.*");
// dataCountList = executeQueryOneLine(sessionPool, "select count(*) from
// root.*");
} catch (BaseException e) {
logger.error("发生错误!!!");
e.printStackTrace();
}
}
int dataCount = 0;
for (String dataCountStr : dataCountList) {
dataCount += Integer.parseInt(dataCountStr);
}
DataCountVO dataCountVO = new DataCountVO();
dataCountVO.setStorageGroupCount(groupCount);
dataCountVO.setDeviceCount(deviceCount);
dataCountVO.setMonitorCount(measurementCount);
dataCountVO.setDataCount(dataCount);
dataCountVO.setVersion(iotdbVersion);
return dataCountVO;
} catch (NumberFormatException e) {
throw new BaseException(ErrorCode.GET_DATA_COUNT_FAIL, ErrorCode.GET_DATA_COUNT_FAIL_MSG);
} finally {
closeSessionPool(sessionPool);
}
}