首页 > 编程语言 > 详细

python 访问hive

时间:2020-09-10 19:45:24      阅读:514      评论:0      收藏:0      [点我收藏+]

1、安装

pip install impyla==0.14.1
pip install pure_sasl==0.5.1
pip install thriftpy==0.3.9
pip install thrift-sasl==0.2.1 
pip install thrift
pip install bitarray

1、报错:thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol ‘c‘
   解决:
   将 C:\Python27\Lib\site-packages\thriftpy\parser\parser.py , line 488
   if url_scheme == ‘‘:
   改为:
   if len(url_scheme) <= 1:
2、报错:TypeError: can‘t concat str to bytes
   定位到错误的最后一条,在init.py第94行(标黄的部分)
   header = struct.pack(">BI", status, len(body))
   #按照网上的提供的办法增加对BODY的处理
   if (type(body) is str):
       body = body.encode()
   self._trans.write(header + body)
   self._trans.flush()

2、使用

import impala.dbapi as ipdb

class HiveControl:
    def __init__(self, db_name=default):
        self.conn = ipdb.connect(host=192.168.XX.XX, port=10000, database=db_name,  user=user, password=password,
auth_mechanism=PLAIN) self.cursor = self.conn.cursor() # 默认为NONE,另外还可以为’NOSASL’, ‘PLAIN’, ‘KERBEROS’, ‘LDAP’, ‘CUSTOM’. def excuteSql(self, sql): try: self.cursor.execute(sql) res = self.cursor.fetchall() except Exception as e: self.cursor.close() self.conn.close() raise (e) self.cursor.close() self.conn.close() return res hiv = HiveControl() print(hiv.excuteSql(show databases))

 

python 访问hive

原文:https://www.cnblogs.com/snailgirl/p/13647713.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!