一、python与hive1通信
#!/usr/bin/python2.7 #hive --service hiveserver >/dev/null 2>/dev/null& #/usr/lib/hive/lib/py import sys from hive_service import ThriftHive from hive_service.ttypes import HiveServerException from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol def hiveExe(sql): try: transport = TSocket.TSocket('*.*.*.*', 10000) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = ThriftHive.Client(protocol) transport.open() client.execute(sql) print "The return value is : " print client.fetchAll() print "............" transport.close() except Thrift.TException, tx: print '%s' % (tx.message) if __name__ == '__main__': hiveExe("select * from project.table")
python和hive1通讯是一件非常容易的事情,因为python所需要的依赖包从/usr/lib/hive/lib/py获取即可,导入到hive的扩张中就可以应用了。
二、python与hive2的通信
#!/usr/bin/python2.7 #hive --service hiveserver2 >/dev/null 2>/dev/null& #install pyhs2,first install cyrus-sasl-devel,gcc,libxml2-devel,libxslt-devel #hiveserver2 is different from hiveserver on authority import pyhs2 conn = pyhs2.connect(host='*.*.*.*',port=10000,authMechanism="PLAIN", user='hive', password='', database='project') cur = conn.cursor() cur.execute("select * from table limit 10") for i in cur.fetch(): print i cur.close() conn.close()
python与hive2通信比较费劲,需要安装的依赖比较多(install pyhs2,first install cyrus-sasl-devel,gcc,libxml2-devel,libxslt-devel)。但是安装完成后编程还是很容易的。
两种通讯有一个共同点,就是必须启动hive服务器。
相关推荐
主要介绍了如何在python中写hive脚本,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
内容包括hive如何安装与启动,以及如何使用python访问hive,希望对大家有帮助。
Python 连接Hive离线方式1
用户应用偏好模型月表(python+hive)
主要介绍了使用Python构造hive insert语句说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
PyHive2 允许在 Python 中轻松使用 HQL(Hive SQL),并允许在 Hive 中轻松使用 Python 对象和 Python 函数。 安装 PyHive2 要求ant(为了构建java文件) 安装 PyHive2 下载源码: git clone 更改您的工作目录...
# 此脚本查找以“--”开头的注释 # ----------------------------------------------示例----------------------------------------- # -- 查找姓名为张三的学生信息 # insert overwrite table student_search ...
python 利用pyhive 连接hiveserver2,系统linux 系统,通过pd 导出excel
主要介绍了python导出hive数据表的schema实例代码,小编觉得还是挺不错的,具有一定借鉴价值,需要的朋友可以参考下
python3.6链接hive和impala的依赖包大全,搞了好久才把这些依赖包搞全,希望给其他有帮助
现在想转行到数据分析师该怎么做? 数据分析师是一个未来10年内都会很火爆...【资料免费领取】简历模板、职场PPT模板、硬核学习资料+PDF资料(SQL、Python、HIVE、HADOOP、大数据等等)https://jinshuju.net/f/fsBfIu
主要介绍了python 实现 hive中类似 lateral view explode的功能示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
NULL 博文链接:https://chaoboma.iteye.com/blog/1953150
Hadoop MapReduce 与 Python 和 Hive 在 python 中为 Hadoop 编写 MapReduce 程序,并使用 Hive 使用类似 SQL 的查询执行 MapReduce 的教程。 这使用带有 python 的 Hadoop Streaming API 来教授使用 MapReduce ...
windows python2.7 连接hive。安装pyhs2,需要提前安装的包以及步骤。亲测有效
今天小编就为大家分享一篇python 操作hive pyhs2方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
centos7 pyhive连接hive(基于kerberos)。由于基于kerberos校验的hive服务器通过python连接的过程很麻烦,故整理文档。
PyHive-0.6.4.tar.gz安装包