python读取hive数据最佳实践

使用pyhive库来连接hive server2提供的对外接口,使用sql语句来对数据进行查询,并处理返回结果。

安装依赖:

yum install python-pip gcc gcc-c++ python-virtualenv cyrus-sasl-devel
pip install pyhive
pip install thift
pip install sasl
pip install thrift-sasl

目前大部分公司都使用cdh来安装整个hadoop的处理平台,可以在cloudera manager中查看HiveServer2的配置。

代码如下:

# -*- coding: utf-8 -*-
from pyhive import hive

conn = hive.Connection(host='HiveServer2 host', port=10000, username='hdfs', database='default')
cursor = conn.cursor()
cursor.execute('select * from demo_table limit 10')
for result in cursor.fetchall():
    print result

参考:

https://github.com/dropbox/PyHive

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容