Session原生API
Session原生API
IoTDB 原生 API 中的 Session 是實現與數據庫交互的核心接口,它集成了豐富的方法,支持數據寫入、查詢以及元數據操作等功能。通過實例化 Session,能夠建立與 IoTDB 服務器的連接,在該連接所構建的環境中執行各類數據庫操作。Session為非線程安全,不能被多線程同時調用。
SessionPool 是 Session 的連接池,推薦使用SessionPool編程。在多線程并發的情形下,SessionPool 能夠合理地管理和分配連接資源,以提升系統性能與資源利用效率。
1 步驟概覽
- 創建連接池實例:初始化一個SessionPool對象,用于管理多個Session實例。
- 執行操作:直接從SessionPool中獲取Session實例,并執行數據庫操作,無需每次都打開和關閉連接。
- 關閉連接池資源:在不再需要進行數據庫操作時,關閉SessionPool,釋放所有相關資源。
2 詳細步驟
本章節用于說明開發的核心流程,并未演示所有的參數和接口,如需了解全部功能及參數請參見: 全量接口說明 或 查閱: 源碼
2.1 創建maven項目
創建一個maven項目,并在pom.xml文件中添加以下依賴(JDK >= 1.8, Maven >= 3.6)
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<!-- 版本號與數據庫版本號相同 -->
<version>${project.version}</version>
</dependency>
</dependencies>2.2 創建連接池實例
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.session.pool.SessionPool;
public class IoTDBSessionPoolExample {
private static SessionPool sessionPool;
public static void main(String[] args) {
// Using nodeUrls ensures that when one node goes down, other nodes are automatically connected to retry
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
nodeUrls.add("127.0.0.1:6668");
sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build();
}
}2.3 執行數據庫操作
2.3.1 數據寫入
在工業場景中,數據寫入可分為以下幾類:多行數據寫入、單設備多行數據寫入,下面按不同場景對寫入接口進行介紹。
多行數據寫入接口
接口說明:支持一次寫入多行數據,每一行對應一個設備一個時間戳的多個測點值。
接口列表:
| 接口名稱 | 功能描述 |
|---|---|
insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) | 插入多行數據,適用于不同測點獨立采集的場景 |
代碼案例:
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.tsfile.enums.TSDataType;
public class SessionPoolExample {
private static SessionPool sessionPool;
public static void main(String[] args) throws IoTDBConnectionException, StatementExecutionException {
// 1. init SessionPool
constructSessionPool();
// 2. execute insert data
insertRecordsExample();
// 3. close SessionPool
closeSessionPool();
}
private static void constructSessionPool() {
// Using nodeUrls ensures that when one node goes down, other nodes are automatically connected to retry
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
nodeUrls.add("127.0.0.1:6668");
sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build();
}
public static void insertRecordsExample() throws IoTDBConnectionException, StatementExecutionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
measurements.add("s2");
measurements.add("s3");
List<String> deviceIds = new ArrayList<>();
List<List<String>> measurementsList = new ArrayList<>();
List<List<Object>> valuesList = new ArrayList<>();
List<Long> timestamps = new ArrayList<>();
List<List<TSDataType>> typesList = new ArrayList<>();
for (long time = 0; time < 500; time++) {
List<Object> values = new ArrayList<>();
List<TSDataType> types = new ArrayList<>();
values.add(1L);
values.add(2L);
values.add(3L);
types.add(TSDataType.INT64);
types.add(TSDataType.INT64);
types.add(TSDataType.INT64);
deviceIds.add(deviceId);
measurementsList.add(measurements);
valuesList.add(values);
typesList.add(types);
timestamps.add(time);
if (time != 0 && time % 100 == 0) {
try {
sessionPool.insertRecords(deviceIds, timestamps, measurementsList, typesList, valuesList);
} catch (IoTDBConnectionException | StatementExecutionException e) {
// solve exception
}
deviceIds.clear();
measurementsList.clear();
valuesList.clear();
typesList.clear();
timestamps.clear();
}
}
try {
sessionPool.insertRecords(deviceIds, timestamps, measurementsList, typesList, valuesList);
} catch (IoTDBConnectionException | StatementExecutionException e) {
// solve exception
}
}
public static void closeSessionPool(){
sessionPool.close();
}
}單設備多行數據寫入接口
接口說明:支持一次寫入單個設備的多行數據,每一行對應一個時間戳的多個測點值。
接口列表:
| 接口名稱 | 功能描述 |
|---|---|
insertTablet(Tablet tablet) | 插入單個設備的多行數據,適用于不同測點獨立采集的場景 |
代碼案例:
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.schema.MeasurementSchema;
public class SessionPoolExample {
private static SessionPool sessionPool;
public static void main(String[] args) throws IoTDBConnectionException, StatementExecutionException {
// 1. init SessionPool
constructSessionPool();
// 2. execute insert data
insertTabletExample();
// 3. close SessionPool
closeSessionPool();
}
private static void constructSessionPool() {
// Using nodeUrls ensures that when one node goes down, other nodes are automatically connected to retry
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
nodeUrls.add("127.0.0.1:6668");
sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build();
}
private static void insertTabletExample() throws IoTDBConnectionException, StatementExecutionException {
/*
* A Tablet example:
* device1
* time s1, s2, s3
* 1, 1, 1, 1
* 2, 2, 2, 2
* 3, 3, 3, 3
*/
// The schema of measurements of one device
// only measurementId and data type in MeasurementSchema take effects in Tablet
List<MeasurementSchema> schemaList = new ArrayList<>();
schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
schemaList.add(new MeasurementSchema("s3", TSDataType.INT64));
Tablet tablet = new Tablet("root.sg.d1", schemaList, 100);
// Method 1 to add tablet data
long timestamp = System.currentTimeMillis();
Random random = new Random();
for (long row = 0; row < 100; row++) {
int rowIndex = tablet.rowSize++;
tablet.addTimestamp(rowIndex, timestamp);
for (int s = 0; s < 3; s++) {
long value = random.nextLong();
tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value);
}
if (tablet.rowSize == tablet.getMaxRowNumber()) {
sessionPool.insertTablet(tablet);
tablet.reset();
}
timestamp++;
}
if (tablet.rowSize != 0) {
sessionPool.insertTablet(tablet);
tablet.reset();
}
}
public static void closeSessionPool(){
sessionPool.close();
}
}2.3.2 SQL操作
SQL操作分為查詢和非查詢兩類操作,對應的接口為executeQuery和executeNonQuery操作,其區別為前者執行的是具體的查詢語句,會返回一個結果集,后者是執行的是增、刪、改操作,不返回結果集。
import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
public class SessionPoolExample {
private static SessionPool sessionPool;
public static void main(String[] args) throws IoTDBConnectionException, StatementExecutionException {
// 1. init SessionPool
constructSessionPool();
// 2. executes a non-query SQL statement, such as a DDL or DML command.
executeQueryExample();
// 3. executes a query SQL statement and returns the result set.
executeNonQueryExample();
// 4. close SessionPool
closeSessionPool();
}
private static void executeNonQueryExample() throws IoTDBConnectionException, StatementExecutionException {
// 1. create a nonAligned time series
sessionPool.executeNonQueryStatement("create timeseries root.test.d1.s1 with dataType = int32");
// 2. set ttl
sessionPool.executeNonQueryStatement("set TTL to root.test.** 10000");
// 3. delete time series
sessionPool.executeNonQueryStatement("delete timeseries root.test.d1.s1");
}
private static void executeQueryExample() throws IoTDBConnectionException, StatementExecutionException {
// 1. execute normal query
try(SessionDataSetWrapper wrapper = sessionPool.executeQueryStatement("select s1 from root.sg1.d1 limit 10")) {
// get DataIterator like JDBC
DataIterator dataIterator = wrapper.iterator();
System.out.println(wrapper.getColumnNames());
System.out.println(wrapper.getColumnTypes());
while (dataIterator.next()) {
StringBuilder builder = new StringBuilder();
for (String columnName : wrapper.getColumnNames()) {
builder.append(dataIterator.getString(columnName) + " ");
}
System.out.println(builder);
}
}
// 2. execute aggregate query
try(SessionDataSetWrapper wrapper = sessionPool.executeQueryStatement("select count(s1) from root.sg1.d1 group by ([0, 40), 5ms) ")) {
// get DataIterator like JDBC
DataIterator dataIterator = wrapper.iterator();
System.out.println(wrapper.getColumnNames());
System.out.println(wrapper.getColumnTypes());
while (dataIterator.next()) {
StringBuilder builder = new StringBuilder();
for (String columnName : wrapper.getColumnNames()) {
builder.append(dataIterator.getString(columnName) + " ");
}
System.out.println(builder);
}
}
}
private static void constructSessionPool() {
// Using nodeUrls ensures that when one node goes down, other nodes are automatically connected to retry
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
nodeUrls.add("127.0.0.1:6668");
sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build();
}
public static void closeSessionPool(){
sessionPool.close();
}
}更多關于結果集及其方法 SessionDataSet.DataIterator 的使用可參考如下示例(其中,getBlob 和 getDate 兩個接口從 V1.3.6 起支持):
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.DateUtils;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.Assert;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SessionExample {
private static SessionPool sessionPool;
public static void main(String[] args)
throws IoTDBConnectionException, StatementExecutionException {
// 1. init SessionPool
constructSessionPool();
// 2. executes a query SQL statement, such as a DDL or DML command.
executeQueryExample();
// 3. close SessionPool
closeSessionPool();
}
private static void executeQueryExample()
throws IoTDBConnectionException, StatementExecutionException {
Tablet tablet =
new Tablet(
"root.sg.d1",
Arrays.asList(
new MeasurementSchema("s1", TSDataType.INT32),
new MeasurementSchema("s2", TSDataType.INT64),
new MeasurementSchema("s3", TSDataType.FLOAT),
new MeasurementSchema("s4", TSDataType.DOUBLE),
new MeasurementSchema("s5", TSDataType.TEXT),
new MeasurementSchema("s6", TSDataType.BOOLEAN),
new MeasurementSchema("s7", TSDataType.TIMESTAMP),
new MeasurementSchema("s8", TSDataType.BLOB),
new MeasurementSchema("s9", TSDataType.STRING),
new MeasurementSchema("s10", TSDataType.DATE),
new MeasurementSchema("s11", TSDataType.TIMESTAMP)),
10);
tablet.addTimestamp(0, 0L);
tablet.addValue("s1", 0, 1);
tablet.addValue("s2", 0, 1L);
tablet.addValue("s3", 0, 0f);
tablet.addValue("s4", 0, 0d);
tablet.addValue("s5", 0, "text_value");
tablet.addValue("s6", 0, true);
tablet.addValue("s7", 0, 1L);
tablet.addValue("s8", 0, new Binary(new byte[] {1}));
tablet.addValue("s9", 0, "string_value");
tablet.addValue("s10", 0, DateUtils.parseIntToLocalDate(20250403));
tablet.initBitMaps();
tablet.bitMaps[10].mark(0);
tablet.rowSize = 1;
sessionPool.insertAlignedTablet(tablet);
try (SessionDataSetWrapper dataSet =
sessionPool.executeQueryStatement("select * from root.sg.d1")) {
SessionDataSet.DataIterator iterator = dataSet.iterator();
int count = 0;
while (iterator.next()) {
count++;
Assert.assertFalse(iterator.isNull("root.sg.d1.s1"));
Assert.assertEquals(1, iterator.getInt("root.sg.d1.s1"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s2"));
Assert.assertEquals(1L, iterator.getLong("root.sg.d1.s2"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s3"));
Assert.assertEquals(0, iterator.getFloat("root.sg.d1.s3"), 0.01);
Assert.assertFalse(iterator.isNull("root.sg.d1.s4"));
Assert.assertEquals(0, iterator.getDouble("root.sg.d1.s4"), 0.01);
Assert.assertFalse(iterator.isNull("root.sg.d1.s5"));
Assert.assertEquals("text_value", iterator.getString("root.sg.d1.s5"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s6"));
Assert.assertTrue(iterator.getBoolean("root.sg.d1.s6"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s7"));
Assert.assertEquals(new Timestamp(1), iterator.getTimestamp("root.sg.d1.s7"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s8"));
Assert.assertEquals(new Binary(new byte[] {1}), iterator.getBlob("root.sg.d1.s8"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s9"));
Assert.assertEquals("string_value", iterator.getString("root.sg.d1.s9"));
Assert.assertFalse(iterator.isNull("root.sg.d1.s10"));
Assert.assertEquals(
DateUtils.parseIntToLocalDate(20250403), iterator.getDate("root.sg.d1.s10"));
Assert.assertTrue(iterator.isNull("root.sg.d1.s11"));
Assert.assertNull(iterator.getTimestamp("root.sg.d1.s11"));
Assert.assertEquals(new Timestamp(0), iterator.getTimestamp("Time"));
Assert.assertFalse(iterator.isNull("Time"));
}
Assert.assertEquals(tablet.rowSize, count);
}
}
private static void constructSessionPool() {
List<String> nodeUrls = new ArrayList<>();
nodeUrls.add("127.0.0.1:6667");
sessionPool =
new SessionPool.Builder()
.nodeUrls(nodeUrls)
.user("root")
.password("root")
.maxSize(3)
.build();
}
public static void closeSessionPool() {
sessionPool.close();
}
}3 全量接口說明
3.1 參數列表
Session具有如下的字段,可以通過構造函數或Session.Builder方式設置如下參數
| 字段名 | 類型 | 說明 |
|---|---|---|
nodeUrls | List<String> | 數據庫節點的 URL 列表,支持多節點連接 |
username | String | 用戶名 |
password | String | 密碼 |
fetchSize | int | 查詢結果的默認批量返回大小 |
useSSL | boolean | 是否啟用 SSL |
trustStore | String | 信任庫路徑 |
trustStorePwd | String | 信任庫密碼 |
queryTimeoutInMs | long | 查詢的超時時間,單位毫秒 |
enableRPCCompression | boolean | 是否啟用 RPC 壓縮 |
connectionTimeoutInMs | int | 連接超時時間,單位毫秒 |
zoneId | ZoneId | 會話的時區設置 |
thriftDefaultBufferSize | int | Thrift 默認緩沖區大小 |
thriftMaxFrameSize | int | Thrift 最大幀大小 |
defaultEndPoint | TEndPoint | 默認的數據庫端點信息 |
defaultSessionConnection | SessionConnection | 默認的會話連接對象 |
isClosed | boolean | 當前會話是否已關閉 |
enableRedirection | boolean | 是否啟用重定向功能 |
enableRecordsAutoConvertTablet | boolean | 是否啟用記錄自動轉換為 Tablet 的功能 |
deviceIdToEndpoint | Map<String, TEndPoint> | 設備 ID 和數據庫端點的映射關系 |
endPointToSessionConnection | Map<TEndPoint, SessionConnection> | 數據庫端點和會話連接的映射關系 |
executorService | ScheduledExecutorService | 用于定期更新節點列表的線程池 |
availableNodes | INodeSupplier | 可用節點的供應器 |
enableQueryRedirection | boolean | 是否啟用查詢重定向功能 |
version | Version | 客戶端的版本號,用于與服務端的兼容性判斷 |
enableAutoFetch | boolean | 是否啟用自動獲取功能 |
maxRetryCount | int | 最大重試次數 |
retryIntervalInMs | long | 重試的間隔時間,單位毫秒 |
3.2 接口列表
3.2.1 元數據管理
| 方法名 | 功能描述 | 參數解釋 |
|---|---|---|
createDatabase(String database) | 創建數據庫 | database: 數據庫名稱 |
deleteDatabase(String database) | 刪除指定數據庫 | database: 要刪除的數據庫名稱 |
deleteDatabases(List<String> databases) | 批量刪除數據庫 | databases: 要刪除的數據庫名稱列表 |
createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) | 創建單個時間序列 | path: 時間序列路徑,dataType: 數據類型,encoding: 編碼類型,compressor: 壓縮類型 |
createAlignedTimeseries(...) | 創建對齊時間序列 | 設備ID、測點列表、數據類型列表、編碼列表、壓縮類型列表 |
createMultiTimeseries(...) | 批量創建時間序列 | 多個路徑、數據類型、編碼、壓縮類型、屬性、標簽、別名等 |
deleteTimeseries(String path) | 刪除時間序列 | path: 要刪除的時間序列路徑 |
deleteTimeseries(List<String> paths) | 批量刪除時間序列 | paths: 要刪除的時間序列路徑列表 |
setSchemaTemplate(String templateName, String prefixPath) | 設置模式模板 | templateName: 模板名稱,prefixPath: 應用模板的路徑 |
createSchemaTemplate(Template template) | 創建模式模板 | template: 模板對象 |
dropSchemaTemplate(String templateName) | 刪除模式模板 | templateName: 要刪除的模板名稱 |
addAlignedMeasurementsInTemplate(...) | 添加對齊測點到模板 | 模板名稱、測點路徑列表、數據類型、編碼類型、壓縮類型 |
addUnalignedMeasurementsInTemplate(...) | 添加非對齊測點到模板 | 同上 |
deleteNodeInTemplate(String templateName, String path) | 刪除模板中的節點 | templateName: 模板名稱,path: 要刪除的路徑 |
countMeasurementsInTemplate(String name) | 統計模板中測點數量 | name: 模板名稱 |
isMeasurementInTemplate(String templateName, String path) | 檢查模板中是否存在某測點 | templateName: 模板名稱,path: 測點路徑 |
isPathExistInTemplate(String templateName, String path) | 檢查模板中路徑是否存在 | 同上 |
showMeasurementsInTemplate(String templateName) | 顯示模板中的測點 | templateName: 模板名稱 |
showMeasurementsInTemplate(String templateName, String pattern) | 按模式顯示模板中的測點 | templateName: 模板名稱,pattern: 匹配模式 |
showAllTemplates() | 顯示所有模板 | 無參數 |
showPathsTemplateSetOn(String templateName) | 顯示模板應用的路徑 | templateName: 模板名稱 |
showPathsTemplateUsingOn(String templateName) | 顯示模板實際使用的路徑 | 同上 |
unsetSchemaTemplate(String prefixPath, String templateName) | 取消路徑的模板設置 | prefixPath: 路徑,templateName: 模板名稱 |
3.2.2 數據寫入
| 方法名 | 功能描述 | 參數解釋 |
|---|---|---|
insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, Object... values) | 插入單條記錄 | deviceId: 設備ID,time: 時間戳,measurements: 測點列表,types: 數據類型列表,values: 值列表 |
insertRecord(String deviceId, long time, List<String> measurements, List<String> values) | 插入單條記錄 | deviceId: 設備ID,time: 時間戳,measurements: 測點列表,values: 值列表 |
insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<Object>> valuesList) | 插入多條記錄 | deviceIds: 設備ID列表,times: 時間戳列表,measurementsList: 測點列表列表,valuesList: 值列表 |
insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) | 插入多條記錄 | 同上,增加 typesList: 數據類型列表 |
insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) | 插入單設備的多條記錄 | deviceId: 設備ID,times: 時間戳列表,measurementsList: 測點列表列表,typesList: 類型列表,valuesList: 值列表 |
insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList, boolean haveSorted) | 插入排序后的單設備多條記錄 | 同上,增加 haveSorted: 數據是否已排序 |
insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) | 插入字符串格式的單設備記錄 | deviceId: 設備ID,times: 時間戳列表,measurementsList: 測點列表,valuesList: 值列表 |
insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList, boolean haveSorted) | 插入排序的字符串格式單設備記錄 | 同上,增加 haveSorted: 數據是否已排序 |
insertAlignedRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values) | 插入單條對齊記錄 | deviceId: 設備ID,time: 時間戳,measurements: 測點列表,types: 類型列表,values: 值列表 |
insertAlignedRecord(String deviceId, long time, List<String> measurements, List<String> values) | 插入字符串格式的單條對齊記錄 | deviceId: 設備ID,time: 時間戳,measurements: 測點列表,values: 值列表 |
insertAlignedRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<Object>> valuesList) | 插入多條對齊記錄 | deviceIds: 設備ID列表,times: 時間戳列表,measurementsList: 測點列表,valuesList: 值列表 |
insertAlignedRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) | 插入多條對齊記錄 | 同上,增加 typesList: 數據類型列表 |
insertAlignedRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) | 插入單設備的多條對齊記錄 | 同上 |
insertAlignedRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList, boolean haveSorted) | 插入排序的單設備多條對齊記錄 | 同上,增加 haveSorted: 數據是否已排序 |
insertAlignedStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) | 插入字符串格式的單設備對齊記錄 | deviceId: 設備ID,times: 時間戳列表,measurementsList: 測點列表,valuesList: 值列表 |
insertAlignedStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList, boolean haveSorted) | 插入排序的字符串格式單設備對齊記錄 | 同上,增加 haveSorted: 數據是否已排序 |
insertTablet(Tablet tablet) | 插入單個Tablet數據 | tablet: 要插入的Tablet數據 |
insertTablet(Tablet tablet, boolean sorted) | 插入排序的Tablet數據 | 同上,增加 sorted: 數據是否已排序 |
insertAlignedTablet(Tablet tablet) | 插入對齊的Tablet數據 | tablet: 要插入的Tablet數據 |
insertAlignedTablet(Tablet tablet, boolean sorted) | 插入排序的對齊Tablet數據 | 同上,增加 sorted: 數據是否已排序 |
insertTablets(Map<String, Tablet> tablets) | 批量插入多個Tablet數據 | tablets: 設備ID到Tablet的映射表 |
insertTablets(Map<String, Tablet> tablets, boolean sorted) | 批量插入排序的多個Tablet數據 | 同上,增加 sorted: 數據是否已排序 |
insertAlignedTablets(Map<String, Tablet> tablets) | 批量插入多個對齊Tablet數據 | tablets: 設備ID到Tablet的映射表 |
insertAlignedTablets(Map<String, Tablet> tablets, boolean sorted) | 批量插入排序的多個對齊Tablet數據 | 同上,增加 sorted: 數據是否已排序 |
3.2.3 數據刪除
| 方法名 | 功能描述 | 參數解釋 |
|---|---|---|
deleteTimeseries(String path) | 刪除單個時間序列 | path: 時間序列路徑 |
deleteTimeseries(List<String> paths) | 批量刪除時間序列 | paths: 時間序列路徑列表 |
deleteData(String path, long endTime) | 刪除指定路徑的歷史數據 | path: 路徑,endTime: 結束時間戳 |
deleteData(List<String> paths, long endTime) | 批量刪除路徑的歷史數據 | paths: 路徑列表,endTime: 結束時間戳 |
deleteData(List<String> paths, long startTime, long endTime) | 刪除路徑時間范圍內的歷史數據 | 同上,增加 startTime: 起始時間戳 |
3.2.4 數據查詢
| 方法名 | 功能描述 | 參數解釋 |
|---|---|---|
executeQueryStatement(String sql) | 執行查詢語句 | sql: 查詢SQL語句 |
executeQueryStatement(String sql, long timeoutInMs) | 執行帶超時的查詢語句 | sql: 查詢SQL語句,timeoutInMs: 查詢超時時間(毫秒),默認取服務器配置即60s |
executeRawDataQuery(List<String> paths, long startTime, long endTime) | 查詢指定路徑的原始數據 | paths: 查詢路徑列表,startTime: 起始時間戳,endTime: 結束時間戳 |
executeRawDataQuery(List<String> paths, long startTime, long endTime, long timeOut) | 查詢指定路徑的原始數據(帶超時) | 同上,增加 timeOut: 超時時間 |
executeLastDataQuery(List<String> paths) | 查詢最新數據 | paths: 查詢路徑列表 |
executeLastDataQuery(List<String> paths, long lastTime) | 查詢指定時間的最新數據 | paths: 查詢路徑列表,lastTime: 指定的時間戳 |
executeLastDataQuery(List<String> paths, long lastTime, long timeOut) | 查詢指定時間的最新數據(帶超時) | 同上,增加 timeOut: 超時時間 |
executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes) | 查詢單個設備的最新數據 | db: 數據庫名,device: 設備名,sensors: 傳感器列表,isLegalPathNodes: 是否合法路徑節點 |
executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations) | 執行聚合查詢 | paths: 查詢路徑列表,aggregations: 聚合類型列表 |
executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime) | 執行帶時間范圍的聚合查詢 | 同上,增加 startTime: 起始時間戳,endTime: 結束時間戳 |
executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval) | 執行帶時間間隔的聚合查詢 | 同上,增加 interval: 時間間隔 |
executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval, long slidingStep) | 執行滑動窗口聚合查詢 | 同上,增加 slidingStep: 滑動步長 |
fetchAllConnections() | 獲取所有活動連接信息 | 無參數 |
3.2.5 系統狀態與備份
| 方法名 | 功能描述 | 參數解釋 |
|---|---|---|
getBackupConfiguration() | 獲取備份配置信息 | 無參數 |
fetchAllConnections() | 獲取所有活動的連接信息 | 無參數 |
getSystemStatus() | 獲取系統狀態 | 已廢棄,默認返回 SystemStatus.NORMAL |