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 ...
随机推荐
- [BZOJ1123]:[POI2008]BLO(塔尖)
题目传送门 题目描述 Byteotia城市有n个towns.m条双向roads.每条road连接两个不同的towns,没有重复的road.所有towns连通. 输入格式 输入n,m及m条边. 输出格式 ...
- word 之 插入删除空行
好久没有写程序了.有些手生: 在用C#对word进行直接开发操作过程中,为了文档的美观,我们会插入或删除空行. 1.插入空行的代码很简单. Selection 类型的TypeParagraph()函数 ...
- phpstorm 比较修改过的代码 version control
- C++中的各种容器实现原理
C++ 容器及选用总结 vector 拥有一段连续的内存空间 list 就是数据结构中的双向链表 deque 的动态数组首尾都开放 set 有序的容器,红黑树的平衡二叉检索树的数据结构 multise ...
- LC 650. 2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...
- JavaScript 格式化数字成金额格式
在看公司一个项目的JavaScript代码时,发现一段JavaScript代码,是把数字格式化成金额格式 比如: 12345.678 格式化成 12,345.68 看完代码后,google了一下,发 ...
- IOS input框轻点无效修复方法
FastClick.prototype.focus = function(targetElement) { targetElement.focus();//加入这一句话就OK了 };
- redis 之django-redis
redis之django-redis 自定义连接池 这种方式跟普通py文件操作redis一样,代码如下: views.py import redis from django.shortcuts i ...
- Ansible 直接请求远程主机执行命令
ansible -all -i host1.abc.com, -m ping #注意主机名称后面的逗号,就算一台主机也是必须的.多台主机可以用逗号隔开 ansible all -i host1.abc ...
- java:shiroProject
1.backend_system Maven Webapp: LoginController.java: package com.shiro.demo.controller; import org ...