remove IoTDBDataType in rpc, use int32 instead

This commit is contained in:
qiaojialin 2019-08-23 22:50:48 +08:00
parent 895c9ba031
commit c9d040ca4d
9 changed files with 31 additions and 94 deletions

View File

@ -156,7 +156,7 @@ public class Client {
request.deviceId = rowBatch.deviceId;
for (MeasurementSchema measurementSchema: rowBatch.measurements) {
request.addToMeasurements(measurementSchema.getMeasurementId());
request.addToTypes(Utils.getIoTDBDataTypeByTSDataType(measurementSchema.getType()));
request.addToTypes(measurementSchema.getType().ordinal());
}
request.setTimestamps(Utils.getTimeBuffer(rowBatch));
request.setValues(Utils.getValueBuffer(rowBatch));

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.service.rpc.thrift.TSDataValue;
import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet;
import org.apache.iotdb.service.rpc.thrift.TSRowRecord;
@ -105,7 +104,7 @@ public class Utils {
field.setNull();
r.getFields().add(field);
} else {
TSDataType dataType = getTSDataTypeByRPCType(value.getType());
TSDataType dataType = TSDataType.valueOf(value.getType());
Field field = new Field(dataType);
addFieldAccordingToDataType(field, dataType, value);
r.getFields().add(field);
@ -116,30 +115,6 @@ public class Utils {
return records;
}
private static TSDataType getTSDataTypeByRPCType(IoTDBDataType type) {
switch (type) {
case BOOLEAN: return TSDataType.BOOLEAN;
case FLOAT: return TSDataType.FLOAT;
case DOUBLE: return TSDataType.DOUBLE;
case INT32: return TSDataType.INT32;
case INT64: return TSDataType.INT64;
case TEXT: return TSDataType.TEXT;
default: throw new RuntimeException("data type not supported: " + type);
}
}
public static IoTDBDataType getIoTDBDataTypeByTSDataType(TSDataType type) {
switch (type) {
case BOOLEAN: return IoTDBDataType.BOOLEAN;
case FLOAT: return IoTDBDataType.FLOAT;
case DOUBLE: return IoTDBDataType.DOUBLE;
case INT32: return IoTDBDataType.INT32;
case INT64: return IoTDBDataType.INT64;
case TEXT: return IoTDBDataType.TEXT;
default: throw new RuntimeException("data type not supported: " + type);
}
}
/**
*
* @param field -the field need to add new data

View File

@ -281,7 +281,7 @@ public class IoTDBQueryResultSetTest {
} else {
value.setInt_val((int) item[3 * i + 3]);
}
value.setType(Utils.getIoTDBDataTypeByTSDataType((TSDataType) item[3 * i + 2]));
value.setType(item[3 * i + 2].toString());
}
values.add(value);
}

View File

@ -125,7 +125,7 @@ public class UtilsTest {
} else {
value.setBinary_val(ByteBuffer.wrap(((String) item[3 * i + 3]).getBytes()));
}
value.setType(Utils.getIoTDBDataTypeByTSDataType((TSDataType) item[3 * i + 2]));
value.setType(item[3 * i + 2].toString());
}
values.add(value);
}

View File

@ -24,7 +24,6 @@ import java.util.List;
import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.utils.QueryDataSetUtils;
import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Path;
@ -36,7 +35,6 @@ public class BatchInsertPlan extends PhysicalPlan {
private String deviceId;
private String[] measurements;
private TSDataType[] dataTypes;
private List<IoTDBDataType> dataTypeList;
private long[] times;
private ByteBuffer timeBuffer;
@ -61,14 +59,7 @@ public class BatchInsertPlan extends PhysicalPlan {
setMeasurements(measurements);
}
public BatchInsertPlan(String deviceId, String[] measurements, List<IoTDBDataType> dataTypes) {
super(false, OperatorType.BATCHINSERT);
this.deviceId = deviceId;
this.measurements = measurements;
setDataTypes(dataTypes);
}
public BatchInsertPlan(String deviceId, String[] measurements, IoTDBDataType[] dataTypes) {
public BatchInsertPlan(String deviceId, String[] measurements, List<Integer> dataTypes) {
super(false, OperatorType.BATCHINSERT);
this.deviceId = deviceId;
this.measurements = measurements;
@ -197,13 +188,9 @@ public class BatchInsertPlan extends PhysicalPlan {
this.times = new long[rows];
QueryDataSetUtils.readTimesFromBuffer(buffer, rows);
QueryDataSetUtils.readValuesFromBuffer(buffer, dataTypeList, measurementSize, rows);
QueryDataSetUtils.readValuesFromBuffer(buffer, dataTypes, measurementSize, rows);
}
public void setDataTypeList(List<IoTDBDataType> dataTypeList) {
this.dataTypeList = dataTypeList;
setDataTypes(dataTypeList);
}
public String getDeviceId() {
return deviceId;
@ -230,17 +217,10 @@ public class BatchInsertPlan extends PhysicalPlan {
return dataTypes;
}
public void setDataTypes(List<IoTDBDataType> dataTypes) {
public void setDataTypes(List<Integer> dataTypes) {
this.dataTypes = new TSDataType[dataTypes.size()];
for (int i = 0; i < dataTypes.size(); i++) {
this.dataTypes[i] = QueryDataSetUtils.getTSDataTypeByIoTDBDataType(dataTypes.get(i));
}
}
public void setDataTypes(IoTDBDataType[] dataTypes) {
this.dataTypes = new TSDataType[dataTypes.length];
for (int i = 0; i < dataTypes.length; i++) {
this.dataTypes[i] = QueryDataSetUtils.getTSDataTypeByIoTDBDataType(dataTypes[i]);
this.dataTypes[i] = TSDataType.values()[dataTypes.get(i)];
}
}

View File

@ -1023,7 +1023,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
batchInsertPlan.setRowCount(req.size);
batchInsertPlan.setTimeBuffer(req.timestamps);
batchInsertPlan.setValueBuffer(req.values);
batchInsertPlan.setDataTypeList(req.types);
batchInsertPlan.setDataTypes(req.types);
boolean isAllSuccessful = true;

View File

@ -18,7 +18,6 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.service.rpc.thrift.TSDataValue;
import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet;
import org.apache.iotdb.service.rpc.thrift.TSRowRecord;
@ -99,36 +98,13 @@ public class QueryDataSetUtils {
"data type %s is not supported when convert data at server",
f.getDataType().toString()));
}
value.setType(getIoTDBDataTypeByTSDataType(f.getDataType()));
value.setType(f.getDataType().toString());
}
tsRowRecord.getValues().add(value);
}
return tsRowRecord;
}
public static IoTDBDataType getIoTDBDataTypeByTSDataType(TSDataType type) {
switch (type) {
case BOOLEAN: return IoTDBDataType.BOOLEAN;
case FLOAT: return IoTDBDataType.FLOAT;
case DOUBLE: return IoTDBDataType.DOUBLE;
case INT32: return IoTDBDataType.INT32;
case INT64: return IoTDBDataType.INT64;
case TEXT: return IoTDBDataType.TEXT;
default: throw new RuntimeException("data type not supported: " + type);
}
}
public static TSDataType getTSDataTypeByIoTDBDataType(IoTDBDataType type) {
switch (type) {
case BOOLEAN: return TSDataType.BOOLEAN;
case FLOAT: return TSDataType.FLOAT;
case DOUBLE: return TSDataType.DOUBLE;
case INT32: return TSDataType.INT32;
case INT64: return TSDataType.INT64;
case TEXT: return TSDataType.TEXT;
default: throw new RuntimeException("data type not supported: " + type);
}
}
public static long[] readTimesFromBuffer(ByteBuffer buffer, int size) {
long[] times = new long[size];
@ -138,16 +114,26 @@ public class QueryDataSetUtils {
return times;
}
public static Object[] readValuesFromBuffer(ByteBuffer buffer, List<Integer> types,
int columns, int size) {
TSDataType[] dataTypes = new TSDataType[types.size()];
for (int i = 0; i < dataTypes.length; i++) {
dataTypes[i] = TSDataType.values()[types.get(i)];
}
return readValuesFromBuffer(buffer, dataTypes, columns, size);
}
/**
* @param buffer data values
* @param columns column number
* @param size value count in each column
*/
public static Object[] readValuesFromBuffer(ByteBuffer buffer, List<IoTDBDataType> types,
public static Object[] readValuesFromBuffer(ByteBuffer buffer, TSDataType[] types,
int columns, int size) {
Object[] values = new Object[columns];
for (int i = 0; i < columns; i++) {
switch (types.get(i)) {
switch (types[i]) {
case BOOLEAN:
boolean[] boolValues = new boolean[size];
for (int index = 0; index < size; index++) {
@ -196,7 +182,7 @@ public class QueryDataSetUtils {
default:
throw new UnSupportedDataTypeException(
String.format("data type %s is not supported when convert data at client",
types.get(i)));
types[i]));
}
}
return values;

View File

@ -18,14 +18,14 @@
*/
package org.apache.iotdb.db.engine.storagegroup;
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.db.engine.MetadataManagerHelper;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
import org.apache.iotdb.db.exception.StorageGroupProcessorException;
import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.service.rpc.thrift.IoTDBDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.record.TSRecord;
import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint;
@ -82,9 +82,9 @@ public class StorageGroupProcessorTest {
String[] measurements = new String[2];
measurements[0] = "s0";
measurements[1] = "s1";
IoTDBDataType[] dataTypes = new IoTDBDataType[2];
dataTypes[0] = IoTDBDataType.INT32;
dataTypes[1] = IoTDBDataType.INT64;
List<Integer> dataTypes = new ArrayList<>();
dataTypes.add(TSDataType.INT32.ordinal());
dataTypes.add(TSDataType.INT64.ordinal());
BatchInsertPlan batchInsertPlan1 = new BatchInsertPlan("root.vehicle.d0", measurements, dataTypes);
@ -131,7 +131,7 @@ public class StorageGroupProcessorTest {
@Test
public void testSeqAndUnSeqSyncClose() throws StorageGroupProcessorException {
public void testSeqAndUnSeqSyncClose() {
for (int j = 21; j <= 30; j++) {
TSRecord record = new TSRecord(j, deviceId);

View File

@ -28,10 +28,6 @@ enum TS_StatusCode {
INVALID_HANDLE_STATUS
}
enum IoTDBDataType {
BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT
}
// The return status of a remote request
struct TS_Status {
1: required TS_StatusCode statusCode
@ -197,7 +193,7 @@ struct TSDataValue{
5: optional double float_val
6: optional double double_val
7: optional binary binary_val
8: optional IoTDBDataType type
8: optional string type
}
struct TSRowRecord{
@ -269,7 +265,7 @@ struct TSBatchInsertionReq {
2: required list<string> measurements
3: required binary values
4: required binary timestamps
5: required list<IoTDBDataType> types
5: required list<i32> types
6: required i32 size
}