In root directory:
mvn clean install -pl session -am -DskipTests
<dependencies> <dependency> <groupId>org.apache.iotdb</groupId> <artifactId>iotdb-session</artifactId> <version>0.12.0</version> </dependency> </dependencies>
Here we show the commonly used interfaces and their parameters in the Native API:
Session(String host, int rpcPort) Session(String host, String rpcPort, String username, String password) Session(String host, int rpcPort, String username, String password)
Session.open()
Session.close()
void setStorageGroup(String storageGroupId)
void deleteStorageGroup(String storageGroup) void deleteStorageGroups(List<String> storageGroups)
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)
void deleteTimeseries(String path) void deleteTimeseries(List<String> paths)
void deleteData(String path, long time) void deleteData(List<String> paths, long time)
void insertRecord(String deviceId, long time, List<String> measurements, List<String> values)
void insertTablet(Tablet tablet)
void insertTablets(Map<String, Tablet> tablet)
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
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)
SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime)
SessionDataSet executeQueryStatement(String sql)
void executeNonQueryStatement(String sql)
void testInsertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
or
void testInsertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)
void testInsertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)
void testInsertRecord(String deviceId, long time, List<String> measurements, List<String> values)
or
void testInsertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values)
void testInsertTablet(Tablet tablet)
To get more information of the following interfaces, please view session/src/main/java/org/apache/iotdb/session/Session.java
The sample code of using these interfaces is in example/session/src/main/java/org/apache/iotdb/SessionExample.java,which provides an example of how to open an IoTDB session, execute a batch insertion.
We provide a connection pool (`SessionPool) for Native API. Using the interface, you need to define the pool size.
If you can not get a session connection in 60 seconds, there is a warning log but the program will hang.
If a session has finished an operation, it will be put back to the pool automatically. If a session connection is broken, the session will be removed automatically and the pool will try to create a new session and redo the operation.
For query operations:
SessionDataSetWrapper
;SessionDataSetWrapper
, if you have not scanned all the data in it and stop to use it, you have to call SessionPool.closeResultSet(wrapper)
manually;hasNext()
and next()
of a SessionDataSetWrapper
and there is an exception, then you have to call SessionPool.closeResultSet(wrapper)
manually;getColumnNames()
of SessionDataSetWrapper
to get the column names of query result;Examples: session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
Or example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java
void open(boolean enableRPCCompression)
Open a session, with a parameter to specify whether to enable RPC compression. Please pay attention that this RPC compression status of client must comply with the status of IoTDB server
void insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values)
Insert one record, in a way that user has to provide the type information of each measurement, which is different from the original insertRecord() interface. The values should be provided in their primitive types. This interface is more proficient than the one without type parameters.
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList)
Insert multiple records with type parameters. This interface is more proficient than the one without type parameters.
void insertTablet(Tablet tablet, boolean sorted)
An additional insertTablet() interface that providing a “sorted” parameter indicating if the tablet is in order. A sorted tablet may accelerate the insertion process.
void insertTablets(Map<String, Tablet> tablets)
A new insertTablets() for inserting multiple tablets.
void insertTablets(Map<String, Tablet> tablets, boolean sorted)
insertTablets() with an additional “sorted” parameter.
void testInsertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values) void testInsertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) void testInsertTablet(Tablet tablet, boolean sorted) void testInsertTablets(Map<String, Tablet> tablets) void testInsertTablets(Map<String, Tablet> tablets, boolean sorted)
The above interfaces are newly added to test responsiveness of new insert interfaces.
void createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor, Map<String, String> props, Map<String, String> tags, Map<String, String> attributes, String measurementAlias)
Create a timeseries with path, datatype, encoding and compression. Additionally, users can provide props, tags, attributes and 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)
Create multiple timeseries with a single method. Users can provide props, tags, attributes and measurementAlias as well for detailed timeseries information.
boolean checkTimeseriesExists(String path)
Add a method to check whether the specific timeseries exists.
public Session(String host, int rpcPort, String username, String password, boolean isEnableCacheLeader)
Open a session and specifies whether the Leader cache is enabled. Note that this interface improves performance for distributed IoTDB, but adds less cost to the client for stand-alone IoTDB.