Session And TsFile API
在使用Session、TsFIle API时,如果您调用的方法需要以字符串形式传入物理量(measurement)、设备(device)、数据库(database)、路径(path)等参数,请保证所传入字符串与使用 SQL 语句时的写法一致,下面是一些帮助您理解的例子。具体代码示例可以参考:example/session/src/main/java/org/apache/iotdb/SyntaxConventionRelatedExample.java
- 以创建时间序列 createTimeseries 为例:
1. public void createTimeseries(
2. String path,
3. TSDataType dataType,
4. TSEncoding encoding,
5. CompressionType compressor)
6. throws IoTDBConnectionException, StatementExecutionException;
如果您希望创建时间序列 root.sg.a,root.sg
open in new window.a.``“b,root.sg
open in new window.111,您使用的 SQL 语句应该如下所示:
1. create timeseries root.sg.a with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;
3. # 路径结点名中包含特殊字符,时间序列各结点为["root","sg","a.`\"b"]
4. create timeseries root.sg.`a."b` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;
6. # 路径结点名为实数
7. create timeseries root.sg.`111` with datatype=FLOAT,encoding=PLAIN,compressor=SNAPPY;
您在调用 createTimeseries 方法时,应该按照如下方法赋值 path 字符串,保证 path 字符串内容与使用 SQL 时一致:
1. // 时间序列 root.sg.a
2. String path = "root.sg.a";
4. // 时间序列 root.sg.`a``"b`
5. String path = "root.sg.`a``\"b`";
7. // 时间序列 root.sg.`111`
8. String path = "root.sg.`111`";
- 以插入数据 insertRecord 为例:
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;
如果您希望向时间序列 root.sg.a,root.sg
open in new window.a.``“b,root.sg
open in new window.111中插入数据,您使用的 SQL 语句应该如下所示:
1. insert into root.sg(timestamp, a, `a."b`, `111`) values (1, 2, 2, 2);
您在调用 insertRecord 方法时,应该按照如下方法赋值 deviceId 和 measurements:
1. // deviceId 为 root.sg
2. String deviceId = "root.sg";
4. // measurements
5. String[] measurements = new String[]{"a", "`a.\"b`", "`111`"};
6. List<String> measurementList = Arrays.asList(measurements);
- 以查询数据 executeRawDataQuery 为例:
1. public SessionDataSet executeRawDataQuery(
2. List<String> paths,
3. long startTime,
4. long endTime)
5. throws StatementExecutionException, IoTDBConnectionException;
如果您希望查询时间序列 root.sg.a,root.sg
open in new window.a.``“b,root.sg
open in new window.111的数据,您使用的 SQL 语句应该如下所示:
1. select a from root.sg
3. # 路径结点名中包含特殊字符
4. select `a."b` from root.sg;
6. # 路径结点名为实数
7. select `111` from root.sg
您在调用 executeRawDataQuery 方法时,应该按照如下方法赋值 paths:
1. // paths
2. String[] paths = new String[]{"root.sg.a", "root.sg.`a.\"b`", "root.sg.`111`"};
3. List<String> pathList = Arrays.asList(paths);
