Hive 教程(九)-python with hive
本文介绍用 python 远程连接 hive,此时需要 hive 启动 hiveserver2 服务
windows 下报如下错误
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2
不好玩,还是 linux 吧
安装依赖包
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
最麻烦的是安装 sasl,出现异常参考下面的异常记录
python 操作 hive
官网方法-pyhs2
import pyhs2 ## 连接 hve 和 数据库
with pyhs2.connect(host='192.168.10.10',
port=10000,
authMechanism="PLAIN",
user='postgres',
password='postgres',
database='hive1') as conn:
with conn.cursor() as cur:
#Show databases
print cur.getDatabases() #Execute query
cur.execute("show tables") # 注意没有 分号 #Return column info from query
print cur.getSchema() cur.execute('select * from hive_01 limit 3')
#Fetch table results
for i in cur.fetch():
print i
其他方法-pyhive
from pyhive import hive conn = hive.Connection(host='192.168.10.10', port=10000, username="postgres", password='postgres', auth='CUSTOM')
cursor = conn.cursor()
cursor.execute('SHOW DATABASES')
# 打印结果
for result in cursor.fetchall():
print(result)
auth
其他方法-impyla
其他依赖
pip install six
pip install bit_array
pip install thriftpy
demo
from impala.dbapi import connect
conn = connect(host ='****',port = ****)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print cursor.description # 打印结果集的schema
results = cursor.fetchall()
异常记录
安装 sasl 报错如下
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
error: command 'gcc' failed with exit status 1
解决方案
Ubuntu 系统的话可能需要先装好 libsasl2-dev
apt-get install libsasl2-dev
CentOS 系统需要预先装好 python-devel 和 cyrus-sasl-devel
yum install gcc-c++ python-devel.x86_64 cyrus-sasl-devel.x86_64
参考资料:
https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-PythonClientDriver 官网
https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl 第三方包下载地址
https://www.jianshu.com/p/a0ff0a4495a1 Python 连接hive(Linux)
https://www.jianshu.com/p/99581dce8309 本文后面有编译python脚本
https://blog.csdn.net/clany888/article/details/82989068 pyhive and impyla 两种方式
https://www.cnblogs.com/chushiyaoyue/p/5628882.html pyhs2 方式,写的代码多
http://www.zhangdongshengtech.com/article-detials/267 pyhive
https://www.cnblogs.com/free-easy0000/p/9638982.html 异常记录
https://www.jianshu.com/p/9dd3a741a8ba 也总结了几种方式
https://www.360kuai.com/pc/9026a62a8775d368f?cota=4&kuai_so=1&tj_url=so_rec&sign=360_57c3bbd1&refer_scene=so_1
https://blog.csdn.net/bigdataf/article/details/78479331 Windows pyhs2下模块安装,没试过
Hive 教程(九)-python with hive的更多相关文章
- HIVE教程
完整PDF下载:<HIVE简明教程> 前言 Hive是对于数据仓库进行管理和分析的工具.但是不要被“数据仓库”这个词所吓倒,数据仓库是很复杂的东西,但是如果你会SQL,就会发现Hive是那 ...
- 【Hadoop/Hive/mapreduce】系列之使用union all 命令之后如何对hive表格使用python进行去重
业务场景大概是这样的,这里由两个hive表格,tableA 和 tableB, 格式内容都是这样的: uid cate1 cate2 在hive QL中,我们知道union有着自动去重的功能,但是那是 ...
- python 连接 hive
1.python连接hive,其实是连接hiveserver,连接的包的impyla impyla安装: error: cc1plus 没有文件或目录 需要安装gcc 和g++,并且版本保持一致 er ...
- Hive 教程(十)-UDF
hive 虽然自带了很多函数,但是毕竟有限,无法满足所有业务场景,用户可以自定义函数来实现特定功能 UDF user define function,用户自定义函数 可以分为 3 类 UDF:一进一出 ...
- Hive 教程(二)-认知hive
在大数据领域,hive 的位置非常重要,排名前三的大数据工具为 spark.hive.kafka 什么是hive 在大数据领域有 3 种需求场景:传输.存储.计算: hive 是一个处理海量的结构化数 ...
- python 读取hive数据
话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...
- Hive(九)Hive 执行过程实例分析
一.Hive 执行过程概述 1.概述 (1) Hive 将 HQL 转换成一组操作符(Operator),比如 GroupByOperator, JoinOperator 等 (2)操作符 Opera ...
- Hive扩展功能(九)--Hive的行级更新操作(Update)
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这三部机, 每部主机的用户名都为centos ...
- Hive教程(1)
1. 介绍 Apache Hive可以使用SQL来读,写,管理分布式存储的大数据集,结构可以投射到已经存储的数据上,命令行工具和JDBC驱动可以让用户连接到Hive. 2. 安装和配置 你可以下载Hi ...
随机推荐
- 初学 Nginx (一) SSI 的作用
SSI:Server Side Include,是一种基于服务端的网页制作技术, Nginx ssi 的例子如下: It took a little while to figure this out ...
- spark feature
spark推测执行:当成功的Task数超过总Task数的75%(可通过参数spark.speculation.quantile设置)时,再统计所有成功的Tasks的运行时间,得到一个中位数,用这个中位 ...
- flask 第四篇 模板语言jinja2
是时候开始写个前端了,Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符 ...
- **高效的MySql 随机读取数据
一直以为mysql随机查询几条数据,就用 SELECT * FROM `table` ORDER BYRAND() LIMIT 5 就可以了. 但是真正测试一下才发现这样效率非常低.一个15万余条的库 ...
- Druid连接池(无框架)
关于连接池有不少技术可以用,例如c3p0,druid等等,因为druid有监控平台,性能在同类产品中算top0的.所以我采用的事druid连接池. 首先熟悉一个技术,我们要搞明白,为什么要用他, 他能 ...
- CAD二次开发中各类多段线的dxf组码
Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; ed.WriteMessag ...
- springboot2.0数据制作为excel表格
注意:由于公司需要大量导出数据成excel表格,因此在网上找了方法,亲测有效. 声明:该博客参考于https://blog.csdn.net/long530439142/article/details ...
- flutter json转字符串 字符串转json
一段json字符串 var jsonStr = '{\"errorCode\": \"0\", \"message\": \"成功 ...
- kafka Windows安装
1:安装JDK. 2:安装Zookeeper 下载地址:https://zookeeper.apache.org/releases.html 下载后,解压放在目录D:\bigdata(本文所用的目录) ...
- Eclipse进行Debug时断点上有一个斜杠,并且debug没有停在断点处
断点上有斜杠,这是由于设置了Skip All Breakpoints的缘故,调试会忽略所有断点,执行完,只需取消Skip All Breakpoints即可,操作:Run-->Skip All ...