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.
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:
<execution><id>generate-thrift-sources-java</id><phase>generate-sources</phase><goals><goal>compile</goal></goals><configuration><generator>java</generator><thriftExecutable>${thrift.exec.absolute.path}</thriftExecutable><thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot></configuration></execution>
- Referring to this setting, add the following content to the pom.xml file to generate the native interface for Rust:
<execution><id>generate-thrift-sources-rust</id><phase>generate-sources</phase><goals><goal>compile</goal></goals><configuration><generator>rs</generator><thriftExecutable>${thrift.exec.absolute.path}</thriftExecutable><thriftSourceRoot>${basedir}/src/main/thrift</thriftSourceRoot><includes>**/common.thrift,**/client.thrift</includes><outputDirectory>${project.build.directory}/generated-sources-rust</outputDirectory></configuration></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
// open a sessionTSOpenSessionResp openSession(1:TSOpenSessionReq req);// close a sessionTSStatus closeSession(1:TSCloseSessionReq req);// run an SQL statement in batchTSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req);// execute SQL statement in batchTSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req);// execute query SQL statementTSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req);// execute insert, delete and update SQL statementTSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req);// fetch next query resultTSFetchResultsResp fetchResults(1:TSFetchResultsReq req)// fetch meta dataTSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req)// cancel a queryTSStatus cancelOperation(1:TSCancelOperationReq req);// close a query datasetTSStatus closeOperation(1:TSCloseOperationReq req);// get time zoneTSGetTimeZoneResp getTimeZone(1:i64 sessionId);// set time zoneTSStatus setTimeZone(1:TSSetTimeZoneReq req);// get server's propertiesServerProperties getProperties();// CREATE DATABASETSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup);// create timeseriesTSStatus createTimeseries(1:TSCreateTimeseriesReq req);// create multi timeseriesTSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req);// delete timeseriesTSStatus deleteTimeseries(1:i64 sessionId, 2:list<string> path)// delete sttorage groupsTSStatus deleteStorageGroups(1:i64 sessionId, 2:list<string> storageGroup);// insert recordTSStatus insertRecord(1:TSInsertRecordReq req);// insert record in string formatTSStatus insertStringRecord(1:TSInsertStringRecordReq req);// insert tabletTSStatus insertTablet(1:TSInsertTabletReq req);// insert tablets in batchTSStatus insertTablets(1:TSInsertTabletsReq req);// insert records in batchTSStatus insertRecords(1:TSInsertRecordsReq req);// insert records of one deviceTSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);// insert records in batch as string formatTSStatus insertStringRecords(1:TSInsertStringRecordsReq req);// test the latency of innsert tablet,caution:no data will be inserted, only for test latencyTSStatus testInsertTablet(1:TSInsertTabletReq req);// test the latency of innsert tablets,caution:no data will be inserted, only for test latencyTSStatus testInsertTablets(1:TSInsertTabletsReq req);// test the latency of innsert record,caution:no data will be inserted, only for test latencyTSStatus testInsertRecord(1:TSInsertRecordReq req);// test the latency of innsert record in string format,caution:no data will be inserted, only for test latencyTSStatus testInsertStringRecord(1:TSInsertStringRecordReq req);// test the latency of innsert records,caution:no data will be inserted, only for test latencyTSStatus testInsertRecords(1:TSInsertRecordsReq req);// test the latency of innsert records of one device,caution:no data will be inserted, only for test latencyTSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);// test the latency of innsert records in string formate,caution:no data will be inserted, only for test latencyTSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req);// delete dataTSStatus deleteData(1:TSDeleteDataReq req);// execute raw data queryTSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req);// request a statement id from serveri64 requestStatementId(1:i64 sessionId);