本文讲述下远程连接Hive遇到的一些问题
一、CentOS连接Hive
尝试使用CentOS 7远程连接Hive,首先安装好需要的相关包
pip install pyhive pip install thrift yum install cyrus-sasl-devel.x86_64 pip install sasl pip install thrift_sasl
连接Hive
$python
>>> from pyhive import hive
>>> conn = hive.Connection(host='192.168.12.5', port=10000, username='root', database='behavior_labels')
>>> cur=conn.cursor()
>>> cur.execute('SHOW TABLES')
>>> cur.fetchall()
二、Windows连接Hive
1.使用pyhive连接hive(连接未成功,可跳过)
安装好连接hive所需的包
pip install pyhive pip install thrift pip install sasl #此步需要先安装visualcppbuildtools_full.exe,不成功的话下载https://www.lfd.uci.edu/~gohlke/pythonlibs/的包 pip install thrift_sasl
C:\Users\Administrator> python >>> from pyhive import hive >>> conn = hive.Connection(host='192.168.12.5', port=10000, username='root', database='behavior_labels')
报错:thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'
经过在GitHub和Stack Overflow查看资料,推测是sasl不支持windows版本,则使用impala连接hive
2.使用impala连接hive
1)当 python 版本是2.7时
pip2 install impyla pip2 install thrift_sasl
>>> from impala.dbapi import connect
>>> conn = connect(host='192.168.12.5', port=10000, auth_mechanism='PLAIN', user='root', password='*', database='behavior_labels')
>>> cur=conn.cursor()
>>> cur.execute('SHOW TABLES')
>>> cur.fetchall()
显示hive中的table表即成功
2)python版本是3.6时
安装前需把相关的包卸载干净,然后重新安装对应的版本
pip3 uninstall sasl #运行时报错module 'sasl' has no attribute 'Client',说明该包没有删除干净,需要手动删除文件 pip3 install impyla pip3 install pure-sasl pip3 install thrift_sasl==0.2.1 --no-deps
>>> from impala.dbapi import connect
运行报错:thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol 'c' ,需要在文件"C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\thriftpy\parser\parser.py"中第488行代码
if url_scheme == '':
with open(path) as fh:
data = fh.read()
改为
if len(url_scheme) <=1:
with open(path) as fh:
data = fh.read()
>>> conn = connect(host='192.168.12.5', port=10000, auth_mechanism='PLAIN', user='root', password='5606603', database='behavior_labels')
报错:TypeError: can't concat str to bytes 需要在File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-p
ackages\thrift_sasl\__init__.py"第94行代码
def _send_message(self, status, body):
header = struct.pack(">BI", status, len(body))
self._trans.write(header + body)
self._trans.flush()
改为
def _send_message(self, status, body):
header = struct.pack(">BI", status, len(body))
if(type(body) is str):
body = body.encode()
self._trans.write(header + body)
self._trans.flush()
到此基本就没问题了,打开python3,开始连接hive
>>> from impala.dbapi import connect
>>> conn = connect(host='192.168.12.5', port=10000, auth_mechanism='PLAIN', user='root', password='*', database='behavior_labels')
>>> cur=conn.cursor()
>>> cur.execute('SHOW TABLES')
>>> cur.fetchall()
参考资料: https://blog.csdn.net/Xiblade/article/details/82318294
本文由走马兰台 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。
以上所述就是小编给大家介绍的《Windows连接linux中hive问题》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
深入浅出WebAssembly
于航 / 电子工业出版社 / 2018-11 / 128.00元
WebAssembly是一种新的二进制格式,它可以方便地将C/C++等静态语言的代码快速地“运行”在浏览器中,这一特性为前端密集计算场景提供了无限可能。不仅如此,通过WebAssembly技术,我们还可以将基于Unity等游戏引擎开发的大型游戏快速地移植到Web端。WebAssembly技术现在已经被计划设计成W3C的标准,众多浏览器厂商已经提供了对其MVP版本标准的支持。在Google I/O ......一起来看看 《深入浅出WebAssembly》 这本书的介绍吧!