Apache IoTDB 提供多种原生写入接口,包括单设备单行写入 (insertRecord)、多设备多行同时写入 (insertRecords)、单设备多行同时写入(insertRecordsOfOneDevice 与 insertTablet),用户可根据自己的写入场景和写入负载灵活选择不同的写入接口
void insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values)
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)
void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)
void insertTablet(Tablet tablet)
public class Tablet {
/** deviceId of this tablet */
public String prefixPath;
/** the list of measurement schemas for creating the tablet */
private List<MeasurementSchema> schemas;
/** timestamps in this tablet */
public long[] timestamps;
/** each object is a primitive type array, which represents values of one measurement */
public Object[] values;
/** each bitmap represents the existence of each value in the current column. */
public BitMap[] bitMaps;
/** the number of rows to include in this tablet */
public int rowSize;
/** the maximum number of rows for this tablet */
private int maxRowNumber;
/** whether this tablet store data of aligned timeseries or not */
private boolean isAligned;
}
使用场景:批量插入单设备的多行数据,数据需按时间对齐,网络开销较 insertRecordsOfOneDevice 更小
参数介绍:关键数据结构 Tablet 类
insertTablet vs. insertRecordsOfOneDevice
void insertTablets(Map<String, Tablet> tablets)
类型推断是自动创建元数据的一部分。当数据均是 String 类型时,我们可以使用如下接口,根据 value 的值进行类型推断。例如:value 为 “true” ,就可以自动推断为布尔类型。value 为 “3.2” ,就可以自动推断为数值类型。服务器需要做类型推断,可能会有额外耗时,速度较无需类型推断的写入慢。
void insertRecord(String deviceId, long time, List<String> measurements, List<String> values)
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
对齐时间序列的写入使用 insertAlignedXXX 接口,其余与上述接口类似: