@Test public void serialize() { IoTDBOptions options = new IoTDBOptions(); options.setTimeseriesOptionList(Lists.newArrayList(new IoTDBOptions.TimeseriesOption("root.sg.D01.temperature"))); DefaultIoTSerializationSchema serializationSchema = new DefaultIoTSerializationSchema(); Map<String,String> tuple = new HashMap(); tuple.put("device", "root.sg.D01"); tuple.put("timestamp", "1581861293000"); tuple.put("measurements", "temperature"); tuple.put("types", "DOUBLE"); tuple.put("values", "36.5"); Event event = serializationSchema.serialize(tuple); assertEquals(tuple.get("device"), event.getDevice()); assertEquals(tuple.get("timestamp"), String.valueOf(event.getTimestamp())); assertEquals(tuple.get("measurements"), event.getMeasurements().get(0)); assertEquals(tuple.get("types"), event.getTypes().get(0).toString()); assertEquals(tuple.get("values"), String.valueOf(event.getValues().get(0))); }
@Override public Event serialize(Map<String, String> tuple) { if (tuple == null) { return null; } String device = tuple.get(fieldDevice); String ts = tuple.get(fieldTimestamp); Long timestamp = ts == null ? System.currentTimeMillis() : Long.parseLong(ts); List<String> measurements = null; if (tuple.get(fieldMeasurements) != null) { measurements = Arrays.asList(tuple.get(fieldMeasurements).split(separator)); } List<TSDataType> types = new ArrayList<>(); for (String type : tuple.get(fieldTypes).split(separator)) { types.add(TSDataType.valueOf(type)); } List<Object> values = new ArrayList<>(); String[] valuesStr = tuple.get(fieldValues).split(separator); for (int i = 0; i < valuesStr.length; i++) { switch (types.get(i)) { case INT64: values.add(Long.parseLong(valuesStr[i])); break; case DOUBLE: values.add(Double.parseDouble(valuesStr[i])); break; case INT32: values.add(Integer.parseInt(valuesStr[i])); break; case TEXT: values.add(valuesStr[i]); break; case FLOAT: values.add(Float.parseFloat(valuesStr[i])); break; case BOOLEAN: values.add(Boolean.parseBoolean(valuesStr[i])); break; } } return new Event(device, timestamp, measurements, types, values); }
DefaultIoTSerializationSchema implements IoTSerializationSchema<Map<String, String>> { @Override public Event serialize(Map<String, String> tuple) { if (tuple == null) { return null; } String device = tuple.get(fieldDevice); String ts = tuple.get(fieldTimestamp); Long timestamp = ts == null ? System.currentTimeMillis() : Long.parseLong(ts); List<String> measurements = null; if (tuple.get(fieldMeasurements) != null) { measurements = Arrays.asList(tuple.get(fieldMeasurements).split(separator)); } List<TSDataType> types = new ArrayList<>(); for (String type : tuple.get(fieldTypes).split(separator)) { types.add(TSDataType.valueOf(type)); } List<Object> values = new ArrayList<>(); String[] valuesStr = tuple.get(fieldValues).split(separator); for (int i = 0; i < valuesStr.length; i++) { switch (types.get(i)) { case INT64: values.add(Long.parseLong(valuesStr[i])); break; case DOUBLE: values.add(Double.parseDouble(valuesStr[i])); break; case INT32: values.add(Integer.parseInt(valuesStr[i])); break; case TEXT: values.add(valuesStr[i]); break; case FLOAT: values.add(Float.parseFloat(valuesStr[i])); break; case BOOLEAN: values.add(Boolean.parseBoolean(valuesStr[i])); break; } } return new Event(device, timestamp, measurements, types, values); } }
DefaultIoTSerializationSchema implements IoTSerializationSchema<Map<String, String>> { @Override public Event serialize(Map<String, String> tuple) { if (tuple == null) { return null; } String device = tuple.get(fieldDevice); String ts = tuple.get(fieldTimestamp); Long timestamp = ts == null ? System.currentTimeMillis() : Long.parseLong(ts); List<String> measurements = null; if (tuple.get(fieldMeasurements) != null) { measurements = Arrays.asList(tuple.get(fieldMeasurements).split(separator)); } List<TSDataType> types = new ArrayList<>(); for (String type : tuple.get(fieldTypes).split(separator)) { types.add(TSDataType.valueOf(type)); } List<Object> values = new ArrayList<>(); String[] valuesStr = tuple.get(fieldValues).split(separator); for (int i = 0; i < valuesStr.length; i++) { switch (types.get(i)) { case INT64: values.add(Long.parseLong(valuesStr[i])); break; case DOUBLE: values.add(Double.parseDouble(valuesStr[i])); break; case INT32: values.add(Integer.parseInt(valuesStr[i])); break; case TEXT: values.add(valuesStr[i]); break; case FLOAT: values.add(Float.parseFloat(valuesStr[i])); break; case BOOLEAN: values.add(Boolean.parseBoolean(valuesStr[i])); break; } } return new Event(device, timestamp, measurements, types, values); }  }
DefaultIoTSerializationSchema implements IoTSerializationSchema<Map<String, String>> { @Override public Event serialize(Map<String, String> tuple) { if (tuple == null) { return null; } String device = tuple.get(fieldDevice); String ts = tuple.get(fieldTimestamp); Long timestamp = ts == null ? System.currentTimeMillis() : Long.parseLong(ts); List<String> measurements = null; if (tuple.get(fieldMeasurements) != null) { measurements = Arrays.asList(tuple.get(fieldMeasurements).split(separator)); } List<TSDataType> types = new ArrayList<>(); for (String type : tuple.get(fieldTypes).split(separator)) { types.add(TSDataType.valueOf(type)); } List<Object> values = new ArrayList<>(); String[] valuesStr = tuple.get(fieldValues).split(separator); for (int i = 0; i < valuesStr.length; i++) { switch (types.get(i)) { case INT64: values.add(Long.parseLong(valuesStr[i])); break; case DOUBLE: values.add(Double.parseDouble(valuesStr[i])); break; case INT32: values.add(Integer.parseInt(valuesStr[i])); break; case TEXT: values.add(valuesStr[i]); break; case FLOAT: values.add(Float.parseFloat(valuesStr[i])); break; case BOOLEAN: values.add(Boolean.parseBoolean(valuesStr[i])); break; } } return new Event(device, timestamp, measurements, types, values); }  @Override Event serialize(Map<String, String> tuple); String getFieldDevice(); void setFieldDevice(String fieldDevice); String getFieldTimestamp(); void setFieldTimestamp(String fieldTimestamp); String getFieldMeasurements(); void setFieldMeasurements(String fieldMeasurements); String getFieldValues(); void setFieldValues(String fieldValues); String getSeparator(); void setSeparator(String separator); }
DefaultIoTSerializationSchema implements IoTSerializationSchema<Map<String, String>> { @Override public Event serialize(Map<String, String> tuple) { if (tuple == null) { return null; } String device = tuple.get(fieldDevice); String ts = tuple.get(fieldTimestamp); Long timestamp = ts == null ? System.currentTimeMillis() : Long.parseLong(ts); List<String> measurements = null; if (tuple.get(fieldMeasurements) != null) { measurements = Arrays.asList(tuple.get(fieldMeasurements).split(separator)); } List<TSDataType> types = new ArrayList<>(); for (String type : tuple.get(fieldTypes).split(separator)) { types.add(TSDataType.valueOf(type)); } List<Object> values = new ArrayList<>(); String[] valuesStr = tuple.get(fieldValues).split(separator); for (int i = 0; i < valuesStr.length; i++) { switch (types.get(i)) { case INT64: values.add(Long.parseLong(valuesStr[i])); break; case DOUBLE: values.add(Double.parseDouble(valuesStr[i])); break; case INT32: values.add(Integer.parseInt(valuesStr[i])); break; case TEXT: values.add(valuesStr[i]); break; case FLOAT: values.add(Float.parseFloat(valuesStr[i])); break; case BOOLEAN: values.add(Boolean.parseBoolean(valuesStr[i])); break; } } return new Event(device, timestamp, measurements, types, values); }  @Override Event serialize(Map<String, String> tuple); String getFieldDevice(); void setFieldDevice(String fieldDevice); String getFieldTimestamp(); void setFieldTimestamp(String fieldTimestamp); String getFieldMeasurements(); void setFieldMeasurements(String fieldMeasurements); String getFieldValues(); void setFieldValues(String fieldValues); String getSeparator(); void setSeparator(String separator);  }