Skip to main content

Session And TsFile API

...About 2 min

Session And TsFile API

When using the Session and TsFile APIs, if the method you call requires parameters such as measurement, device, database, path in the form of String, please ensure that the parameters passed in the input string is the same as when using the SQL statement, here are some examples to help you understand. Code example could be found at: example/session/src/main/java/org/apache/iotdb/

  1. Take creating a time series createTimeseries as an example:
public void createTimeseries(
    String path,
    TSDataType dataType,
    TSEncoding encoding,
    CompressionType compressor)
    throws IoTDBConnectionException, StatementExecutionException;

If you wish to create the time,`a.``"b`,`111`, the SQL statement you use should look like this:

create timeseries with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;

# node names contain special characters, each node in the time series is ["root","sg","a.`\"b"]
create timeseries`a.``"b` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;

# node names are pure numbers
create timeseries`111` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;

When you call the createTimeseries method, you should assign the path string as follows to ensure that the content of the path string is the same as when using SQL:

// timeseries
String path = "";

// timeseries`a``"b`
String path = "`a``\"b`";

// timeseries`111`
String path = "`111`";
  1. Take inserting data insertRecord as an example:
public void insertRecord(
    String deviceId,
    long time,
    List<String> measurements,
    List<TSDataType> types,
    Object... values)
    throws IoTDBConnectionException, StatementExecutionException;

If you want to insert data into the time series,`a.``"b` ,`111`, the SQL statement you use should be as follows:

insert into, a, `a.``"b`, `111`) values (1, 2, 2, 2);

When you call the insertRecord method, you should assign deviceId and measurements as follows:

// deviceId is
String deviceId = "";

// measurements
String[] measurements = new String[]{"a", "`a.``\"b`", "`111`"};
List<String> measurementList = Arrays.asList(measurements);
  1. Take executeRawDataQuery as an example:
public SessionDataSet executeRawDataQuery(
    List<String> paths, 
    long startTime, 
    long endTime)
    throws StatementExecutionException, IoTDBConnectionException;

If you wish to query the data of the time series,`a.``"b`,`111`, the SQL statement you use should be as follows :

select a from

# node name contains special characters
select `a.``"b` from;

# node names are pure numbers
select `111` from

When you call the executeRawDataQuery method, you should assign paths as follows:

// paths
String[] paths = new String[]{"", "`a.``\"b`", "`111`"};
List<String> pathList = Arrays.asList(paths);

Copyright © 2024 The Apache Software Foundation.
Apache IoTDB, IoTDB, Apache, the Apache feather logo, and the Apache IoTDB project logo are either registered trademarks or trademarks of The Apache Software Foundation in all countries

Have a question? Connect with us on QQ, WeChat, or Slack. Join the community now.