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

  1. Find the pom.xml file in the root directory of the IoTDB source code folder.
  2. 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>
  1. 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>
  1. 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);
  3. // close a session
  4. TSStatus closeSession(1:TSCloseSessionReq req);
  5. // run an SQL statement in batch
  6. TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req);
  7. // execute SQL statement in batch
  8. TSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req);
  9. // execute query SQL statement
  10. TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req);
  11. // execute insert, delete and update SQL statement
  12. TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req);
  13. // fetch next query result
  14. TSFetchResultsResp fetchResults(1:TSFetchResultsReq req)
  15. // fetch meta data
  16. TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req)
  17. // cancel a query
  18. TSStatus cancelOperation(1:TSCancelOperationReq req);
  19. // close a query dataset
  20. TSStatus closeOperation(1:TSCloseOperationReq req);
  21. // get time zone
  22. TSGetTimeZoneResp getTimeZone(1:i64 sessionId);
  23. // set time zone
  24. TSStatus setTimeZone(1:TSSetTimeZoneReq req);
  25. // get server's properties
  26. ServerProperties getProperties();
  27. // CREATE DATABASE
  28. TSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup);
  29. // create timeseries
  30. TSStatus createTimeseries(1:TSCreateTimeseriesReq req);
  31. // create multi timeseries
  32. TSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req);
  33. // delete timeseries
  34. TSStatus deleteTimeseries(1:i64 sessionId, 2:list<string> path)
  35. // delete sttorage groups
  36. TSStatus deleteStorageGroups(1:i64 sessionId, 2:list<string> storageGroup);
  37. // insert record
  38. TSStatus insertRecord(1:TSInsertRecordReq req);
  39. // insert record in string format
  40. TSStatus insertStringRecord(1:TSInsertStringRecordReq req);
  41. // insert tablet
  42. TSStatus insertTablet(1:TSInsertTabletReq req);
  43. // insert tablets in batch
  44. TSStatus insertTablets(1:TSInsertTabletsReq req);
  45. // insert records in batch
  46. TSStatus insertRecords(1:TSInsertRecordsReq req);
  47. // insert records of one device
  48. TSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
  49. // insert records in batch as string format
  50. TSStatus insertStringRecords(1:TSInsertStringRecordsReq req);
  51. // test the latency of innsert tablet,caution:no data will be inserted, only for test latency
  52. TSStatus testInsertTablet(1:TSInsertTabletReq req);
  53. // test the latency of innsert tablets,caution:no data will be inserted, only for test latency
  54. TSStatus testInsertTablets(1:TSInsertTabletsReq req);
  55. // test the latency of innsert record,caution:no data will be inserted, only for test latency
  56. TSStatus testInsertRecord(1:TSInsertRecordReq req);
  57. // test the latency of innsert record in string format,caution:no data will be inserted, only for test latency
  58. TSStatus testInsertStringRecord(1:TSInsertStringRecordReq req);
  59. // test the latency of innsert records,caution:no data will be inserted, only for test latency
  60. TSStatus testInsertRecords(1:TSInsertRecordsReq req);
  61. // test the latency of innsert records of one device,caution:no data will be inserted, only for test latency
  62. TSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
  63. // test the latency of innsert records in string formate,caution:no data will be inserted, only for test latency
  64. TSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req);
  65. // delete data
  66. TSStatus deleteData(1:TSDeleteDataReq req);
  67. // execute raw data query
  68. TSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req);
  69. // request a statement id from server
  70. i64 requestStatementId(1:i64 sessionId);