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/SyntaxConventionRelatedExample.java

  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 series root.sg.a, root.sgopen in new window.`a.``"b`, root.sgopen in new window.`111`, the SQL statement you use should look like this:

create timeseries root.sg.a 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 root.sg.`a.``"b` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;

# node names are pure numbers
create timeseries root.sg.`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 root.sg.a
String path = "root.sg.a";

// timeseries root.sg.`a``"b`
String path = "root.sg.`a``\"b`";

// timeseries root.sg.`111`
String path = "root.sg.`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 root.sg.a, root.sgopen in new window.`a.``"b`, root.sgopen in new window.`111`, the SQL statement you use should be as follows:

insert into root.sg(timestamp, 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 root.sg
String deviceId = "root.sg";

// 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 root.sg.a, root.sgopen in new window.`a.``"b`, root.sgopen in new window.`111`, the SQL statement you use should be as follows :

select a from root.sg

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

# node names are pure numbers
select `111` from root.sg

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

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

Copyright © 2024 The Apache Software Foundation.
Apache and the Apache feather logo are trademarks of The Apache Software Foundation

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