1.通过pyhive连接hive需要的Python包:
3.1 pyhive
3.2 thrift
3.3 sasl
共需要三个包
2.连接Hive
from pyhive import hive
import pandas as pd
cnn=hive.Connection(host=‘localhost’, port=‘10000’, username=‘hive’)
cursor=cnn.cursor()
cursor.execute(“show databases”)
data=pd.DataFrame(cursor.fetchall())
其中sasl在Windows安装下安装需要编译环境,为了方便可直接从https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl下载编译好的包,直接进行安装,比如
C:>pip install sasl-0.2.1-cp37-cp37m-win_amd64.whl
安装完毕,执行代码会报以下错误
from pyhive import hive
conn = hive.Connection(host=‘172.100.0.11’,port=10000)
Traceback (most recent call last):
File “”, line 1, in
File “…\Python37\lib\site-packages\pyhive\hive.py”, line 192, in init
self.transport.open()
File "…\Python37\lib\site-packages\thrift_sasl_init.py", line 79, in open
message=(“Could not start SASL: %s” % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: b’Error in sasl_client_start (-12) SASL library is not initialized
【解决方案】
先直接贴出解决方案,后面再给出分析过程。在Windows中使用管理员权限打开控制台,在控制执行一段命令即可,操作如下。
C:\Windows\system32> FOR /F “usebackq delims=” %A IN (python -c "from importlib import util;import os;print(os.path.join(os.path.dirname(util.find_spec('sasl').origin),'sasl2'))"
) DO (
REG ADD “HKEY_LOCAL_MACHINE\SOFTWARE\Carnegie Mellon\Project Cyrus\SASL Library” /v SearchPath /t REG_SZ /d “%A”
)
datax 报错 File “datax.py”, line 114 print readerRef
解决方案:更换安装目录下bin的对应文件
datax.py, dxprof.y, perftrace.py
/home/datax/plugin/reader/._hdfsreader/plugin.json]不存在. 请检查您的配置文
解决:
但是并未在提示目录找到指定文件
需要通过命令行查看是否有._开头的文件
在datax/plugin目录下执行
find ./* -type f -name “._*er”
将查到的文件全部删除,可通过此命令执行
nd ./* -type f -name “._*er”|xargs rm -rf
再次运行命令即可正常执行 :)