MAC
Install Bison:
Use the following brew command to install the Bison version:
brew install bison
Install Boost: Make sure to install the latest version of Boost.
brew install boost
Check OpenSSL: Make sure the OpenSSL library is installed. The default OpenSSL header file path is “/usr/local/opt/openssl/include”.
If you encounter errors related to OpenSSL not being found during compilation, try adding -Dopenssl.include.dir="".
Ubuntu 16.04+ or Other Debian-based Systems
Use the following commands to install dependencies:
sudo apt-get update sudo apt-get install gcc g++ bison flex libboost-all-dev libssl-dev
CentOS 7.7+/Fedora/Rocky Linux or Other Red Hat-based Systems
Use the yum command to install dependencies:
sudo yum update sudo yum install gcc gcc-c++ boost-devel bison flex openssl-devel
Windows
Set Up the Build Environment
Download and Install Flex, Bison
Install Boost Library
bootstrap.bat and b2.exe in sequence.C:\Program Files (x86)\boost_1_78_0.Install OpenSSL
Clone the source code from git:
git clone https://github.com/apache/iotdb.git
The default main branch is the master branch. If you want to use a specific release version, switch to that branch (e.g., version 1.3.2):
git checkout rc/1.3.2
Run Maven to compile in the IoTDB root directory:
Mac or Linux with glibc version >= 2.32
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp
Linux with glibc version >= 2.31
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT
Linux with glibc version >= 2.17
./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT
Windows using Visual Studio 2022
.\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp
Windows using Visual Studio 2019
.\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 16 2019" -Diotdb-tools-thrift.version=0.14.1.1-msvc142-SNAPSHOT
-DboostIncludeDir="C:\Program Files (x86)\boost_1_78_0" -DboostLibraryDir="C:\Program Files (x86)\boost_1_78_0\stage\lib".After successful compilation, the packaged library files will be located in iotdb-client/client-cpp/target, and you can find the compiled example program under example/client-cpp-example/target.
Q: What are the requirements for the environment on Linux?
A:
./mvnw clean install../mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp.Q: How to resolve the undefined reference to '_libc_single_thread' error during Linux compilation?
A:
-Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT or -Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT to the Maven compile command.Q: What if I need to compile using Visual Studio 2017 or earlier on Windows?
A:
.\mvnw.cmd clean install..\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 15 2017".Here we show the commonly used interfaces and their parameters in the Native API:
void open();
void open(bool enableRPCCompression);
Notice: this RPC compression status of client must comply with that of IoTDB server
void close();
void setStorageGroup(const std::string &storageGroupId);
void deleteStorageGroup(const std::string &storageGroup); void deleteStorageGroups(const std::vector<std::string> &storageGroups);
void createTimeseries(const std::string &path, TSDataType::TSDataType dataType, TSEncoding::TSEncoding encoding, CompressionType::CompressionType compressor); void createMultiTimeseries(const std::vector<std::string> &paths, const std::vector<TSDataType::TSDataType> &dataTypes, const std::vector<TSEncoding::TSEncoding> &encodings, const std::vector<CompressionType::CompressionType> &compressors, std::vector<std::map<std::string, std::string>> *propsList, std::vector<std::map<std::string, std::string>> *tagsList, std::vector<std::map<std::string, std::string>> *attributesList, std::vector<std::string> *measurementAliasList);
void createAlignedTimeseries(const std::string &deviceId, const std::vector<std::string> &measurements, const std::vector<TSDataType::TSDataType> &dataTypes, const std::vector<TSEncoding::TSEncoding> &encodings, const std::vector<CompressionType::CompressionType> &compressors);
void deleteTimeseries(const std::string &path); void deleteTimeseries(const std::vector<std::string> &paths);
bool checkTimeseriesExists(const std::string &path);
void createSchemaTemplate(const Template &templ);
templateName at path prefixPath.void setSchemaTemplate(const std::string &template_name, const std::string &prefix_path);
void unsetSchemaTemplate(const std::string &prefix_path, const std::string &template_name);
// Add aligned measurements to a template void addAlignedMeasurementsInTemplate(const std::string &template_name, const std::vector<std::string> &measurements, const std::vector<TSDataType::TSDataType> &dataTypes, const std::vector<TSEncoding::TSEncoding> &encodings, const std::vector<CompressionType::CompressionType> &compressors); // Add one aligned measurement to a template void addAlignedMeasurementsInTemplate(const std::string &template_name, const std::string &measurement, TSDataType::TSDataType dataType, TSEncoding::TSEncoding encoding, CompressionType::CompressionType compressor); // Add unaligned measurements to a template void addUnalignedMeasurementsInTemplate(const std::string &template_name, const std::vector<std::string> &measurements, const std::vector<TSDataType::TSDataType> &dataTypes, const std::vector<TSEncoding::TSEncoding> &encodings, const std::vector<CompressionType::CompressionType> &compressors); // Add one unaligned measurement to a template void addUnalignedMeasurementsInTemplate(const std::string &template_name, const std::string &measurement, TSDataType::TSDataType dataType, TSEncoding::TSEncoding encoding, CompressionType::CompressionType compressor); // Delete a node in template and its children void deleteNodeInTemplate(const std::string &template_name, const std::string &path);
// Return the amount of measurements inside a template int countMeasurementsInTemplate(const std::string &template_name); // Return true if path points to a measurement, otherwise returne false bool isMeasurementInTemplate(const std::string &template_name, const std::string &path); // Return true if path exists in template, otherwise return false bool isPathExistInTemplate(const std::string &template_name, const std::string &path); // Return all measurements paths inside template std::vector<std::string> showMeasurementsInTemplate(const std::string &template_name); // Return all measurements paths under the designated patter inside template std::vector<std::string> showMeasurementsInTemplate(const std::string &template_name, const std::string &pattern);
It is recommended to use insertTablet to help improve write efficiency.
void insertTablet(Tablet &tablet);
void insertTablets(std::unordered_map<std::string, Tablet *> &tablets);
void insertRecord(const std::string &deviceId, int64_t time, const std::vector<std::string> &measurements, const std::vector<TSDataType::TSDataType> &types, const std::vector<char *> &values);
void insertRecords(const std::vector<std::string> &deviceIds, const std::vector<int64_t> ×, const std::vector<std::vector<std::string>> &measurementsList, const std::vector<std::vector<TSDataType::TSDataType>> &typesList, const std::vector<std::vector<char *>> &valuesList);
void insertRecordsOfOneDevice(const std::string &deviceId, std::vector<int64_t> ×, std::vector<std::vector<std::string>> &measurementsList, std::vector<std::vector<TSDataType::TSDataType>> &typesList, std::vector<std::vector<char *>> &valuesList);
Without type information, server has to do type inference, which may cost some time.
void insertRecord(const std::string &deviceId, int64_t time, const std::vector<std::string> &measurements, const std::vector<std::string> &values); void insertRecords(const std::vector<std::string> &deviceIds, const std::vector<int64_t> ×, const std::vector<std::vector<std::string>> &measurementsList, const std::vector<std::vector<std::string>> &valuesList); void insertRecordsOfOneDevice(const std::string &deviceId, std::vector<int64_t> ×, std::vector<std::vector<std::string>> &measurementsList, const std::vector<std::vector<std::string>> &valuesList);
The Insert of aligned timeseries uses interfaces like insertAlignedXXX, and others are similar to the above interfaces:
void deleteData(const std::string &path, int64_t endTime); void deleteData(const std::vector<std::string> &paths, int64_t endTime); void deleteData(const std::vector<std::string> &paths, int64_t startTime, int64_t endTime);
unique_ptr<SessionDataSet> executeQueryStatement(const std::string &sql);
void executeNonQueryStatement(const std::string &sql);
The sample code of using these interfaces is in:
example/client-cpp-example/src/SessionExample.cppexample/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp (Aligned Timeseries)If the compilation finishes successfully, the example project will be placed under example/client-cpp-example/target
If errors occur when compiling thrift source code, try to downgrade your xcode-commandline from 12 to 11.5
When Building Thrift and downloading packages via “wget”, a possible annoying issue may occur with error message looks like:
Failed to delete cached file C:\Users\Administrator\.m2\repository\.cache\download-maven-plugin\index.ser
Possible fixes:
.m2\repository\.cache" directory and try again.<skipCache>true</skipCache> configuration to the download-maven-plugin maven phase that complains this error.