use of cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException in project iotdb-benchmark by thulab.
the class IoTDBClusterSession method verificationQuery.
/**
* Using in verification
*
* @param verificationQuery
*/
@Override
public Status verificationQuery(VerificationQuery verificationQuery) {
DeviceSchema deviceSchema = verificationQuery.getDeviceSchema();
List<DeviceSchema> deviceSchemas = new ArrayList<>();
deviceSchemas.add(deviceSchema);
List<Record> records = verificationQuery.getRecords();
if (records == null || records.size() == 0) {
return new Status(false, new TsdbException("There are no records in verficationQuery."), "There are no records in verficationQuery.");
}
StringBuffer sql = new StringBuffer();
sql.append(getSimpleQuerySqlHead(deviceSchemas));
Map<Long, List<Object>> recordMap = new HashMap<>();
sql.append(" WHERE time = ").append(records.get(0).getTimestamp());
recordMap.put(records.get(0).getTimestamp(), records.get(0).getRecordDataValue());
for (int i = 1; i < records.size(); i++) {
Record record = records.get(i);
sql.append(" or time = ").append(record.getTimestamp());
recordMap.put(record.getTimestamp(), record.getRecordDataValue());
}
int point = 0;
int line = 0;
try {
SessionDataSetWrapper sessionDataSet = sessions[currSession].executeQueryStatement(sql.toString());
while (sessionDataSet.hasNext()) {
RowRecord rowRecord = sessionDataSet.next();
long timeStamp = rowRecord.getTimestamp();
List<Object> values = recordMap.get(timeStamp);
for (int i = 0; i < values.size(); i++) {
String value = rowRecord.getFields().get(i).toString();
String target = String.valueOf(values.get(i));
if (!value.equals(target)) {
LOGGER.error("Using SQL: " + sql + ",Expected:" + value + " but was: " + target);
} else {
point++;
}
}
line++;
}
sessionDataSet.close();
currSession = (currSession + 1) % sessions.length;
} catch (Exception e) {
LOGGER.error("Query Error: " + sql);
return new Status(false, new TsdbException("Failed to query"), "Failed to query.");
}
if (recordMap.size() != line) {
LOGGER.error("Using SQL: " + sql + ",Expected line:" + recordMap.size() + " but was: " + line);
}
return new Status(true, point);
}
use of cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException in project iotdb-benchmark by thulab.
the class IoTDBSession method deviceQuery.
@Override
public Status deviceQuery(DeviceQuery deviceQuery) throws SQLException, TsdbException {
DeviceSchema deviceSchema = deviceQuery.getDeviceSchema();
String sql = getDeviceQuerySql(deviceSchema, deviceQuery.getStartTimestamp(), deviceQuery.getEndTimestamp());
if (!config.isIS_QUIET_MODE()) {
LOGGER.info("IoTDB:" + sql);
}
List<List<Object>> result = new ArrayList<>();
try {
SessionDataSet sessionDataSet = session.executeQueryStatement(sql);
while (sessionDataSet.hasNext()) {
List<Object> line = new ArrayList<>();
RowRecord rowRecord = sessionDataSet.next();
List<Field> fields = rowRecord.getFields();
line.add(rowRecord.getTimestamp());
for (int i = 0; i < fields.size(); i++) {
line.add(fields.get(i).getStringValue());
}
result.add(line);
}
sessionDataSet.closeOperationHandle();
} catch (Exception e) {
LOGGER.error("Query Error: " + sql + " exception:" + e.getMessage());
return new Status(false, new TsdbException("Failed to query"), "Failed to query.");
}
return new Status(true, 0, sql, result);
}
use of cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException in project iotdb-benchmark by thulab.
the class IoTDBSession method deviceSummary.
@Override
public DeviceSummary deviceSummary(DeviceQuery deviceQuery) throws SQLException, TsdbException {
DeviceSchema deviceSchema = deviceQuery.getDeviceSchema();
int totalLineNumber = 0;
long minTimeStamp = 0, maxTimeStamp = 0;
try {
SessionDataSet sessionDataSet = session.executeQueryStatement(getTotalLineNumberSql(deviceSchema));
RowRecord rowRecord = sessionDataSet.next();
totalLineNumber = Integer.parseInt(rowRecord.getFields().get(0).toString());
sessionDataSet.closeOperationHandle();
sessionDataSet = session.executeQueryStatement(getMaxTimeStampSql(deviceSchema));
rowRecord = sessionDataSet.next();
maxTimeStamp = rowRecord.getTimestamp();
sessionDataSet.closeOperationHandle();
sessionDataSet = session.executeQueryStatement(getMinTimeStampSql(deviceSchema));
rowRecord = sessionDataSet.next();
minTimeStamp = rowRecord.getTimestamp();
sessionDataSet.closeOperationHandle();
} catch (IoTDBConnectionException e) {
throw new TsdbException("Failed to connect to IoTDB:" + e.getMessage());
} catch (StatementExecutionException e) {
throw new TsdbException("Failed to execute statement:" + e.getMessage());
}
return new DeviceSummary(deviceSchema.getDevice(), totalLineNumber, minTimeStamp, maxTimeStamp);
}
use of cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException in project iotdb-benchmark by thulab.
the class SingleNodeJDBCConnection method init.
public void init() throws TsdbException {
int nodeSize = 1;
String[] urls;
if (config.isIS_ALL_NODES_VISIBLE()) {
nodeSize = dbConfig.getHOST().size();
urls = new String[nodeSize];
List<String> clusterHosts = dbConfig.getHOST();
for (int i = 0; i < nodeSize; i++) {
String jdbcUrl = String.format(JDBC_URL, dbConfig.getHOST().get(i), dbConfig.getPORT().get(i));
urls[i] = jdbcUrl;
}
} else {
urls = new String[nodeSize];
urls[0] = String.format(JDBC_URL, dbConfig.getHOST().get(0), dbConfig.getPORT().get(0));
}
connections = new Connection[nodeSize];
for (int i = 0; i < connections.length; i++) {
try {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
org.apache.iotdb.jdbc.Config.rpcThriftCompressionEnable = config.isENABLE_THRIFT_COMPRESSION();
connections[i] = DriverManager.getConnection(urls[i], dbConfig.getUSERNAME(), dbConfig.getPASSWORD());
} catch (Exception e) {
LOGGER.error("Initialize IoTDB failed because ", e);
throw new TsdbException(e);
}
}
}
use of cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException in project iotdb-benchmark by thulab.
the class MsSQLServerDB method registerSchema.
/**
* Called once before each test if CREATE_SCHEMA=true.
*
* @param schemaList schema of devices to register
* @return
*/
@Override
public boolean registerSchema(List<DeviceSchema> schemaList) throws TsdbException {
try {
Statement statement = connection.createStatement();
for (SensorType sensorType : SensorType.values()) {
if (sensorType == SensorType.DOUBLE) {
continue;
}
String sysType = typeMap(sensorType);
String createSQL = String.format(CREATE_TABLE, dbConfig.getDB_NAME(), sysType, sysType, sysType, config.getCOMPRESSION());
statement.execute(createSQL);
}
statement.close();
} catch (SQLException sqlException) {
LOGGER.warn("Failed to register", sqlException);
throw new TsdbException(sqlException);
}
return true;
}
Aggregations