首选python3.7或更高版本。
您必须安装Thrift(0.11.0或更高版本)才能将我们的Thrift文件编译为python代码。
下面是官方安装教程:
http://thrift.apache.org/docs/install/
您可以在https://pypi.org/project/apache-iotdb/上找到Apache IoTDB Python客户端API软件包。
下载命令为:
pip install apache-iotdb
或者,如果您了解thrift的基本用法,则可以在以下位置查看thrift源文件: thrift\src\main\thrift\rpc.thrift,使用thrift -gen py -out ./target/iotdb rpc.thrift生成Python库。
我们在client-py/src/SessionExample.py中提供了一个示例,说明如何使用Thrift库连接到IoTDB,请先仔细阅读,然后再编写自己的代码。
编译C++客户端之前首先需要本地编译Thrift库,compile-tools模块负责编译Thrift,之后再编译client-cpp。
Mac 环境下预安装了Bison 2.3版本,但该版本过低不能够用来编译Thrift。使用Bison 2.3版本是会报以下错误:
invalid directive: '%code'
使用下面brew 命令更新bison版本
brew install bison brew link bison --force
添加环境变量:
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
确保安装较新的Boost版本:
brew install boost brew link boost
确保openssl库已安装,默认的openssl头文件路径为"/usr/local/opt/openssl/include" 如果在编译Thrift过程中出现找不到openssl的错误,尝试添加
-Dopenssl.include.dir=""
Linux下需要确保g++已被安装。
一条命令安装所有依赖库:
Debian/Ubuntu:
sudo apt-get install gcc g++ bison flex libboost-all-dev
CentOS:
yum install gcc g++ bison flex boost-devel
保证你的Windows系统已经搭建好了完整的C/C++的编译构建环境。可以是MSVC,MinGW等。
如使用MS Visual Studio,在安装时需要勾选 Visual Studio C/C++ IDE and compiler(supporting CMake, Clang, MinGW)。
Windows版的 Flex 和 Bison 可以从 SourceForge下载: https://sourceforge.net/projects/winflexbison/
下载后需要将可执行文件重命名为flex.exe和bison.exe以保证编译时能够被找到,添加可执行文件的目录到PATH环境变量中。
Boost官网下载新版本Boost: https://www.boost.org/users/download/
依次执行bootstrap.bat 和 b2.exe,本地编译boost
bootstrap.bat .\b2.exe
为了帮助CMake本地安装好的Boost,在编译client-cpp的mvn命令中需添加:
-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}
CMake需要根据不同编译平台使用不同的生成器。CMake支持的生成器列表如下(cmake --help的结果):
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Borland Makefiles = Generates Borland makefiles.
* NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
Ninja = Generates build.ninja files.
Ninja Multi-Config = Generates build-<Config>.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project fi
编译client-cpp 时的mvn命令中添加 -Dcmake.generator="" 选项来指定使用的生成器名称。 mvn package -Dcmake.generator="Visual Studio 15 2017 [arch]"
Maven 命令中添加"-P client-cpp" 选项编译client-cpp模块。client-cpp需要依赖编译好的thrift,即compile-tools模块。
完整的C++客户端命令如下:
mvn package -P compile-cpp -pl example/client-cpp-example -am -DskipTest
注意在Windows下需提前安装好Boost,并添加以下Maven 编译选项:
-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
例如:
mvn package -P compile-cpp -pl client-cpp,server,example/client-cpp-example -am -D"boost.include.dir"="D:\boost_1_75_0" -D"boost.library.dir"="D:\boost_1_75_0\stage\lib" -DskipTests
编译成功后,打包好的.zip文件将位于:“client-cpp/target/client-cpp-${project.version}-cpp-${os}.zip”
解压后的目录结构如下图所示(Mac):
. +-- client | +-- include | +-- Session.h | +-- TSIService.h | +-- rpc_types.h | +-- rpc_constants.h | +-- thrift | +-- thrift_headers... | +-- lib | +-- libiotdb_session.dylib
本地Maven编译Thrift时如出现以下链接的问题,可以尝试将xcode-commandline版本从12降低到11.5
Maven编译Thrift时需要使用wget下载远端文件,可能出现以下报错:
Failed to delete cached file C:\Users\Administrator\.m2\repository\.cache\download-maven-plugin\index.ser
解决方法:
export GO111MODULE=on export GOPROXY=https://goproxy.io mkdir session_example && cd session_example curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go go mod init session_example go run session_example.go
# get thrift 0.13.0 go get github.com/apache/thrift cd $GOPATH/src/github.com/apache/thrift git checkout 0.13.0 mkdir -p $GOPATH/src/iotdb-client-go-example/session_example cd $GOPATH/src/iotdb-client-go-example/session_example curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go go run session_example.go