Updated on 2023-04-28 GMT+08:00

Java API

IoTDB provides a connection pool (SessionPool) for native APIs. When using the APIs, you only need to specify the pool size to obtain connections from the pool. If you cannot get a connection in 60 seconds, a warning log will be printed, but the program continues to wait.

When a connection is used, it automatically returns to the pool and waits to be used next time. When a connection is damaged, it is deleted from the pool and a new connection is created to perform user operations again.

For query operations:

  1. When SessionPool is used for query, the result set is SessionDataSetWrapper, the encapsulation class of SessionDataSet.
  2. If a query result set is not traversed and you do not want to continue traversing, you need to call closeResultSet to release the connection.
  3. If an exception is reported when you traverse a query result set, you need to call closeResultSet to release the connection.
  4. You can call the getColumnNames() method of SessionDataSetWrapper to obtain the column names in the result set.
Table 1 Sessions APIs and corresponding parameters

Method

Description

  • Session(String host, int rpcPort)
  • Session(String host, String rpcPort, String username, String password)
  • Session(String host, int rpcPort, String username, String password)

Initializes a session.

Session.open()

Opens a session.

Session.close()

Closes a session.

void setStorageGroup(String storageGroupId)

Sets a storage group.

  • void deleteStorageGroup(String storageGroup)
  • void deleteStorageGroups(List<String> storageGroups)

Deletes one or more storage groups.

  • void createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor, Map<String, String> props, Map<String, String> tags, Map<String, String> attributes, String measurementAlias)
  • void createMultiTimeseries(List<String> paths, List<TSDataType> dataTypes, List<TSEncoding> encodings, List<CompressionType> compressors, List<Map<String, String>> propsList, List<Map<String, String>> tagsList, List<Map<String, String>> attributesList, List<String> measurementAliasList)

Creates one or more time series.

  • void deleteTimeseries(String path)
  • void deleteTimeseries(List<String> paths)

Deletes one or more time series.

  • void deleteData(String path, long time)
  • void deleteData(List<String> paths, long time)

Deletes the data of one or more time series before or at a specific time point.

void insertRecord(String deviceId, long time, List<String> measurements, List<String> values)

Inserts a record, which contains the data of multiple measurement points of a device at a timestamp. Servers need to perform type inference, which may take extra time.

void insertTablet(Tablet tablet)

Inserts a tablet, which contains multiple rows of non-empty data blocks. The columns in each row are the same.

void insertTablets(Map<String, Tablet> tablet)

Inserts multiple tablets.

void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)

Inserts multiple records. Servers need to perform type inference, which may take extra time.

void insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values)

Inserts a record, which contains the data of multiple measurement points of a device at a timestamp. With the data type information, servers do not need to perform type inference, improving the performance.

void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)

Inserts multiple records. With the data type information, servers do not need to perform type inference, improving the performance.

submitApplication(SubmitApplicationRequest request)

Used by the client to submit a new application to ResourceManager.

void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)

Inserts multiple records of the same device.

SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime)

Queries raw data. The interval includes the start time but does not include the end time.

SessionDataSet executeQueryStatement(String sql)

Executes query statements.

void executeNonQueryStatement(String sql)

Executes non-query statements.

Table 2 Test APIs

Method

Description

  • void testInsertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
  • void testInsertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)

Tests testInsertRecords. A response is returned immediately after data is transmitted to the server. No data is written.

  • void testInsertRecord(String deviceId, long time, List<String> measurements, List<String> values)
  • void testInsertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values)

Tests insertRecord. A response is returned immediately after data is transmitted to the server. No data is written.

void testInsertTablet(Tablet tablet)

Tests insertTablet. A response is returned immediately after data is transmitted to the server. No data is written.