dairui130

导航

python 读取hive数据

话不多说,直接上代码

from pyhive import hivedef pyhive(hql):
    conn = hive.Connection(host='HiveServer2 host', port=10000, database='ods')
    cursor = conn.cursor()
    cursor.execute(hql)
    for result in cursor.fetchall():
        return result

 

部署时遇到一个问题:

Traceback (most recent call last):
  File "test_pyhive.py", line 7, in <module>
    from pyhive import hive
  File "/usr/lib/python2.7/site-packages/pyhive/hive.py", line 15, in <module>
    from TCLIService import TCLIService
  File "/usr/lib/python2.7/site-packages/TCLIService/TCLIService.py", line 9, in <module>
    from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
ImportError: cannot import name TFrozenDict

解决方法是:

原因是某些包没有关联上,装包时,加上[hive]后缀

pip install pyhive[hive]

 

posted on 2019-03-31 16:44  dairui130  阅读(7892)  评论(1编辑  收藏  举报