python读取hive数据最佳实践

作者: 采菊东篱下 | 来源:发表于2017-11-30 15:39 被阅读262次

使用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

相关文章

网友评论

    本文标题:python读取hive数据最佳实践

    本文链接:https://www.haomeiwen.com/subject/bavvbxtx.html