Rust Native API Native API
IoTDB uses Thrift as a cross language RPC framework, so access to IoTDB can be achieved through the interface provided by Thrift. This document will introduce how to generate a native Rust interface that can access IoTDB.
Dependents
- JDK >= 1.8
- Rust >= 1.0.0
- thrift 0.14.1
- Linux、Macos or like unix
- Windows+bash
Thrift (0.14.1 or higher) must be installed to compile Thrift files into Rust code. The following is the official installation tutorial, and in the end, you should receive a Thrift executable file.
1. http://thrift.apache.org/docs/install/
Compile the Thrift library and generate the Rust native interface
- Find the pom.xml file in the root directory of the IoTDB source code folder.
- Open the pom.xml file and find the following content:
1. <execution>
2. <id>generate-thrift-sources-java</id>
3. <phase>generate-sources</phase>
4. <goals>
5. <goal>compile</goal>
6. </goals>
7. <configuration>
8. <generator>java</generator>
9. <thriftExecutable>${thrift.exec.absolute.path}</thriftExecutable>
10. <thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot>
11. </configuration>
12. </execution>
- Referring to this setting, add the following content to the pom.xml file to generate the native interface for Rust:
1. <execution>
2. <id>generate-thrift-sources-rust</id>
3. <phase>generate-sources</phase>
4. <goals>
5. <goal>compile</goal>
6. </goals>
7. <configuration>
8. <generator>rs</generator>
9. <thriftExecutable>${thrift.exec.absolute.path}</thriftExecutable>
10. <thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot>
11. <includes>**/common.thrift,**/client.thrift</includes>
12. <outputDirectory>${project.build.directory}/generated-sources-rust</outputDirectory>
13. </configuration>
14. </execution>
- In the root directory of the IoTDB source code folder,run
mvn clean generate-sources,
This command will automatically delete the files in iotdb/iotdb-protocol/thrift/target and iotdb/iotdb-protocol/thrift-commons/target, and repopulate the folder with the newly generated throttle file.
Using the Rust native interface
copy iotdb/iotdb-protocol/thrift/target/generated-sources-rust/ and iotdb/iotdb-protocol/thrift-commons/target/generated-sources-rust/ in your project。
rpc interface
1. // open a session
2. TSOpenSessionResp openSession(1:TSOpenSessionReq req);
4. // close a session
5. TSStatus closeSession(1:TSCloseSessionReq req);
7. // run an SQL statement in batch
8. TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req);
10. // execute SQL statement in batch
11. TSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req);
13. // execute query SQL statement
14. TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req);
16. // execute insert, delete and update SQL statement
17. TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req);
19. // fetch next query result
20. TSFetchResultsResp fetchResults(1:TSFetchResultsReq req)
22. // fetch meta data
23. TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req)
25. // cancel a query
26. TSStatus cancelOperation(1:TSCancelOperationReq req);
28. // close a query dataset
29. TSStatus closeOperation(1:TSCloseOperationReq req);
31. // get time zone
32. TSGetTimeZoneResp getTimeZone(1:i64 sessionId);
34. // set time zone
35. TSStatus setTimeZone(1:TSSetTimeZoneReq req);
37. // get server's properties
38. ServerProperties getProperties();
40. // CREATE DATABASE
41. TSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup);
43. // create timeseries
44. TSStatus createTimeseries(1:TSCreateTimeseriesReq req);
46. // create multi timeseries
47. TSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req);
49. // delete timeseries
50. TSStatus deleteTimeseries(1:i64 sessionId, 2:list<string> path)
52. // delete sttorage groups
53. TSStatus deleteStorageGroups(1:i64 sessionId, 2:list<string> storageGroup);
55. // insert record
56. TSStatus insertRecord(1:TSInsertRecordReq req);
58. // insert record in string format
59. TSStatus insertStringRecord(1:TSInsertStringRecordReq req);
61. // insert tablet
62. TSStatus insertTablet(1:TSInsertTabletReq req);
64. // insert tablets in batch
65. TSStatus insertTablets(1:TSInsertTabletsReq req);
67. // insert records in batch
68. TSStatus insertRecords(1:TSInsertRecordsReq req);
70. // insert records of one device
71. TSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
73. // insert records in batch as string format
74. TSStatus insertStringRecords(1:TSInsertStringRecordsReq req);
76. // test the latency of innsert tablet,caution:no data will be inserted, only for test latency
77. TSStatus testInsertTablet(1:TSInsertTabletReq req);
79. // test the latency of innsert tablets,caution:no data will be inserted, only for test latency
80. TSStatus testInsertTablets(1:TSInsertTabletsReq req);
82. // test the latency of innsert record,caution:no data will be inserted, only for test latency
83. TSStatus testInsertRecord(1:TSInsertRecordReq req);
85. // test the latency of innsert record in string format,caution:no data will be inserted, only for test latency
86. TSStatus testInsertStringRecord(1:TSInsertStringRecordReq req);
88. // test the latency of innsert records,caution:no data will be inserted, only for test latency
89. TSStatus testInsertRecords(1:TSInsertRecordsReq req);
91. // test the latency of innsert records of one device,caution:no data will be inserted, only for test latency
92. TSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
94. // test the latency of innsert records in string formate,caution:no data will be inserted, only for test latency
95. TSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req);
97. // delete data
98. TSStatus deleteData(1:TSDeleteDataReq req);
100. // execute raw data query
101. TSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req);
103. // request a statement id from server
104. i64 requestStatementId(1:i64 sessionId);
