Search in sources :

Example 1 with TsdbException

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);
}
Also used : Status(cn.edu.tsinghua.iotdb.benchmark.measurement.Status) HashMap(java.util.HashMap) SessionDataSetWrapper(org.apache.iotdb.session.pool.SessionDataSetWrapper) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) ExecutionException(java.util.concurrent.ExecutionException) StatementExecutionException(org.apache.iotdb.rpc.StatementExecutionException) IoTDBConnectionException(org.apache.iotdb.rpc.IoTDBConnectionException) DeviceSchema(cn.edu.tsinghua.iotdb.benchmark.schema.schemaImpl.DeviceSchema) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) RowRecord(org.apache.iotdb.tsfile.read.common.RowRecord) Record(cn.edu.tsinghua.iotdb.benchmark.entity.Record) RowRecord(org.apache.iotdb.tsfile.read.common.RowRecord) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with TsdbException

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);
}
Also used : Status(cn.edu.tsinghua.iotdb.benchmark.measurement.Status) ArrayList(java.util.ArrayList) SessionDataSet(org.apache.iotdb.session.SessionDataSet) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) ExecutionException(java.util.concurrent.ExecutionException) StatementExecutionException(org.apache.iotdb.rpc.StatementExecutionException) IoTDBConnectionException(org.apache.iotdb.rpc.IoTDBConnectionException) Field(org.apache.iotdb.tsfile.read.common.Field) DeviceSchema(cn.edu.tsinghua.iotdb.benchmark.schema.schemaImpl.DeviceSchema) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) RowRecord(org.apache.iotdb.tsfile.read.common.RowRecord) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with TsdbException

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);
}
Also used : DeviceSchema(cn.edu.tsinghua.iotdb.benchmark.schema.schemaImpl.DeviceSchema) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) RowRecord(org.apache.iotdb.tsfile.read.common.RowRecord) IoTDBConnectionException(org.apache.iotdb.rpc.IoTDBConnectionException) DeviceSummary(cn.edu.tsinghua.iotdb.benchmark.entity.DeviceSummary) SessionDataSet(org.apache.iotdb.session.SessionDataSet) StatementExecutionException(org.apache.iotdb.rpc.StatementExecutionException)

Example 4 with TsdbException

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);
        }
    }
}
Also used : TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException) SQLException(java.sql.SQLException) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException)

Example 5 with TsdbException

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;
}
Also used : SensorType(cn.edu.tsinghua.iotdb.benchmark.entity.enums.SensorType) TsdbException(cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException)

Aggregations

TsdbException (cn.edu.tsinghua.iotdb.benchmark.tsdb.TsdbException)50 DeviceSchema (cn.edu.tsinghua.iotdb.benchmark.schema.schemaImpl.DeviceSchema)24 IoTDBConnectionException (org.apache.iotdb.rpc.IoTDBConnectionException)21 StatementExecutionException (org.apache.iotdb.rpc.StatementExecutionException)21 SQLException (java.sql.SQLException)19 DBConnectException (cn.edu.tsinghua.iotdb.benchmark.exception.DBConnectException)14 Status (cn.edu.tsinghua.iotdb.benchmark.measurement.Status)12 RowRecord (org.apache.iotdb.tsfile.read.common.RowRecord)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 ExecutionException (java.util.concurrent.ExecutionException)8 TimeoutException (java.util.concurrent.TimeoutException)8 Sensor (cn.edu.tsinghua.iotdb.benchmark.entity.Sensor)7 SensorType (cn.edu.tsinghua.iotdb.benchmark.entity.enums.SensorType)7 Record (cn.edu.tsinghua.iotdb.benchmark.entity.Record)6 SessionDataSet (org.apache.iotdb.session.SessionDataSet)6 SessionDataSetWrapper (org.apache.iotdb.session.pool.SessionDataSetWrapper)6 DeviceSummary (cn.edu.tsinghua.iotdb.benchmark.entity.DeviceSummary)5 IOException (java.io.IOException)5 ResultSet (java.sql.ResultSet)4