@Test public void testConvertRowRecords() { final int DATA_TYPE_NUM = 6; Object[][] input = { {100L, "sensor1_boolean", TSDataType.BOOLEAN, false, "sensor1_int32", TSDataType.INT32, 100, "sensor1_int64", TSDataType.INT64, 9999999999L, "sensor1_float", TSDataType.FLOAT, 1.23f, "sensor1_double", TSDataType.DOUBLE, 1004234.435d, "sensor1_text", TSDataType.TEXT, "iotdb-jdbc",}, {200L, "sensor2_boolean", TSDataType.BOOLEAN, true, "sensor2_int32", TSDataType.INT32, null, "sensor2_int64", TSDataType.INT64, -9999999999L, "sensor2_float", TSDataType.FLOAT, null, "sensor2_double", TSDataType.DOUBLE, -1004234.435d, "sensor2_text", TSDataType.TEXT, null,}, {300L, "sensor3_boolean", TSDataType.BOOLEAN, null, "sensor3_int32", TSDataType.INT32, -100, "sensor3_int64", TSDataType.INT64, null, "sensor3_float", TSDataType.FLOAT, -1.23f, "sensor3_double", TSDataType.DOUBLE, null, "sensor3_text", TSDataType.TEXT, "jdbc-iotdb",},}; TSQueryDataSet tsQueryDataSet = new TSQueryDataSet(new ArrayList<>()); for (Object[] item : input) { TSRowRecord record = new TSRowRecord(); record.setTimestamp((long) item[0]); List<String> keys = new ArrayList<>(); List<TSDataValue> values = new ArrayList<>(); for (int i = 0; i < DATA_TYPE_NUM; i++) { keys.add((String) item[3 * i + 1]); TSDataValue value = new TSDataValue(false); if (item[3 * i + 3] == null) { value.setIs_empty(true); } else { if (i == 0) { value.setBool_val((boolean) item[3 * i + 3]); value.setType(((TSDataType) item[3 * i + 2]).toString()); } else if (i == 1) { value.setInt_val((int) item[3 * i + 3]); value.setType(((TSDataType) item[3 * i + 2]).toString()); } else if (i == 2) { value.setLong_val((long) item[3 * i + 3]); value.setType(((TSDataType) item[3 * i + 2]).toString()); } else if (i == 3) { value.setFloat_val((float) item[3 * i + 3]); value.setType(((TSDataType) item[3 * i + 2]).toString()); } else if (i == 4) { value.setDouble_val((double) item[3 * i + 3]); value.setType(((TSDataType) item[3 * i + 2]).toString()); } else { value.setBinary_val(ByteBuffer.wrap(((String) item[3 * i + 3]).getBytes())); value.setType(((TSDataType) item[3 * i + 2]).toString()); } } values.add(value); } record.setValues(values); tsQueryDataSet.getRecords().add(record); } List<RowRecord> convertlist = Utils.convertRowRecords(tsQueryDataSet); int index = 0; for (RowRecord r : convertlist) { assertEquals(input[index][0], r.getTimestamp()); List<Field> fields = r.getFields(); int j = 0; for (Field f : fields) { if (j == 0) { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getBoolV()); } } else if (j == 1) { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getIntV()); } } else if (j == 2) { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getLongV()); } } else if (j == 3) { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getFloatV()); } } else if (j == 4) { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getDoubleV()); } } else { if (input[index][3 * j + 3] == null) { assertTrue(f.isNull()); } else { assertEquals(input[index][3 * j + 3], f.getStringValue()); } } j++; } index++; } }
public static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet) { List<RowRecord> records = new ArrayList<>(); for (TSRowRecord ts : tsQueryDataSet.getRecords()) { RowRecord r = new RowRecord(ts.getTimestamp()); int l = ts.getValuesSize(); for (int i = 0; i < l; i++) { TSDataValue value = ts.getValues().get(i); if (value.is_empty) { Field field = new Field(null); field.setNull(); r.getFields().add(field); } else { TSDataType dataType = TSDataType.valueOf(value.getType()); Field field = new Field(dataType); switch (dataType) { case BOOLEAN: field.setBoolV(value.isBool_val()); break; case INT32: field.setIntV(value.getInt_val()); break; case INT64: field.setLongV(value.getLong_val()); break; case FLOAT: field.setFloatV((float) value.getFloat_val()); break; case DOUBLE: field.setDoubleV(value.getDouble_val()); break; case TEXT: field.setBinaryV(new Binary(value.getBinary_val())); ; break; default: throw new UnSupportedDataTypeException( String.format("data type %s is not supported when convert data at client", dataType)); } r.getFields().add(field); } } records.add(r); } return records; }
Utils { public static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet) { List<RowRecord> records = new ArrayList<>(); for (TSRowRecord ts : tsQueryDataSet.getRecords()) { RowRecord r = new RowRecord(ts.getTimestamp()); int l = ts.getValuesSize(); for (int i = 0; i < l; i++) { TSDataValue value = ts.getValues().get(i); if (value.is_empty) { Field field = new Field(null); field.setNull(); r.getFields().add(field); } else { TSDataType dataType = TSDataType.valueOf(value.getType()); Field field = new Field(dataType); switch (dataType) { case BOOLEAN: field.setBoolV(value.isBool_val()); break; case INT32: field.setIntV(value.getInt_val()); break; case INT64: field.setLongV(value.getLong_val()); break; case FLOAT: field.setFloatV((float) value.getFloat_val()); break; case DOUBLE: field.setDoubleV(value.getDouble_val()); break; case TEXT: field.setBinaryV(new Binary(value.getBinary_val())); ; break; default: throw new UnSupportedDataTypeException( String.format("data type %s is not supported when convert data at client", dataType)); } r.getFields().add(field); } } records.add(r); } return records; } }
Utils { public static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet) { List<RowRecord> records = new ArrayList<>(); for (TSRowRecord ts : tsQueryDataSet.getRecords()) { RowRecord r = new RowRecord(ts.getTimestamp()); int l = ts.getValuesSize(); for (int i = 0; i < l; i++) { TSDataValue value = ts.getValues().get(i); if (value.is_empty) { Field field = new Field(null); field.setNull(); r.getFields().add(field); } else { TSDataType dataType = TSDataType.valueOf(value.getType()); Field field = new Field(dataType); switch (dataType) { case BOOLEAN: field.setBoolV(value.isBool_val()); break; case INT32: field.setIntV(value.getInt_val()); break; case INT64: field.setLongV(value.getLong_val()); break; case FLOAT: field.setFloatV((float) value.getFloat_val()); break; case DOUBLE: field.setDoubleV(value.getDouble_val()); break; case TEXT: field.setBinaryV(new Binary(value.getBinary_val())); ; break; default: throw new UnSupportedDataTypeException( String.format("data type %s is not supported when convert data at client", dataType)); } r.getFields().add(field); } } records.add(r); } return records; }  }
Utils { public static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet) { List<RowRecord> records = new ArrayList<>(); for (TSRowRecord ts : tsQueryDataSet.getRecords()) { RowRecord r = new RowRecord(ts.getTimestamp()); int l = ts.getValuesSize(); for (int i = 0; i < l; i++) { TSDataValue value = ts.getValues().get(i); if (value.is_empty) { Field field = new Field(null); field.setNull(); r.getFields().add(field); } else { TSDataType dataType = TSDataType.valueOf(value.getType()); Field field = new Field(dataType); switch (dataType) { case BOOLEAN: field.setBoolV(value.isBool_val()); break; case INT32: field.setIntV(value.getInt_val()); break; case INT64: field.setLongV(value.getLong_val()); break; case FLOAT: field.setFloatV((float) value.getFloat_val()); break; case DOUBLE: field.setDoubleV(value.getDouble_val()); break; case TEXT: field.setBinaryV(new Binary(value.getBinary_val())); ; break; default: throw new UnSupportedDataTypeException( String.format("data type %s is not supported when convert data at client", dataType)); } r.getFields().add(field); } } records.add(r); } return records; }  static IoTDBConnectionParams parseUrl(String url, Properties info); static void verifySuccess(TS_Status status); static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet); }
Utils { public static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet) { List<RowRecord> records = new ArrayList<>(); for (TSRowRecord ts : tsQueryDataSet.getRecords()) { RowRecord r = new RowRecord(ts.getTimestamp()); int l = ts.getValuesSize(); for (int i = 0; i < l; i++) { TSDataValue value = ts.getValues().get(i); if (value.is_empty) { Field field = new Field(null); field.setNull(); r.getFields().add(field); } else { TSDataType dataType = TSDataType.valueOf(value.getType()); Field field = new Field(dataType); switch (dataType) { case BOOLEAN: field.setBoolV(value.isBool_val()); break; case INT32: field.setIntV(value.getInt_val()); break; case INT64: field.setLongV(value.getLong_val()); break; case FLOAT: field.setFloatV((float) value.getFloat_val()); break; case DOUBLE: field.setDoubleV(value.getDouble_val()); break; case TEXT: field.setBinaryV(new Binary(value.getBinary_val())); ; break; default: throw new UnSupportedDataTypeException( String.format("data type %s is not supported when convert data at client", dataType)); } r.getFields().add(field); } } records.add(r); } return records; }  static IoTDBConnectionParams parseUrl(String url, Properties info); static void verifySuccess(TS_Status status); static List<RowRecord> convertRowRecords(TSQueryDataSet tsQueryDataSet);  }