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:
  1. public void createTimeseries(
  2. String path,
  3. TSDataType dataType,
  4. TSEncoding encoding,
  5. CompressionType compressor)
  6. throws IoTDBConnectionException, StatementExecutionException;

If you wish to create the time series root.sg.a, root.sgSession And TsFile API - 图1open in new window.`a.``“b`, root.sgSession And TsFile API - 图2open in new window.`111`, the SQL statement you use should look like this:

  1. create timeseries root.sg.a with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;
  2. # node names contain special characters, each node in the time series is ["root","sg","a.`\"b"]
  3. create timeseries root.sg.`a."b` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;
  4. # node names are pure numbers
  5. 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:

  1. // timeseries root.sg.a
  2. String path = "root.sg.a";
  3. // timeseries root.sg.`a``"b`
  4. String path = "root.sg.`a``\"b`";
  5. // timeseries root.sg.`111`
  6. String path = "root.sg.`111`";
  1. Take inserting data insertRecord as an example:
  1. public void insertRecord(
  2. String deviceId,
  3. long time,
  4. List<String> measurements,
  5. List<TSDataType> types,
  6. Object... values)
  7. throws IoTDBConnectionException, StatementExecutionException;

If you want to insert data into the time series root.sg.a, root.sgSession And TsFile API - 图3open in new window.`a.``“b`, root.sgSession And TsFile API - 图4open in new window.`111`, the SQL statement you use should be as follows:

  1. 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:

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

If you wish to query the data of the time series root.sg.a, root.sgSession And TsFile API - 图5open in new window.`a.``“b`, root.sgSession And TsFile API - 图6open in new window.`111`, the SQL statement you use should be as follows :

  1. select a from root.sg
  2. # node name contains special characters
  3. select `a."b` from root.sg;
  4. # node names are pure numbers
  5. select `111` from root.sg

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

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