使用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
参考:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有