python操作hive 安装和测试
方法一:使用pyhive库

如上图所示我们需要四个外部包
中间遇到很多报错。我都一一解决了
1.Connection Issue: thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

2.安装sasl 遇到Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools"
解决了 点击
3.遇到
thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'
处理

加上 auth="NOSAL"这个参数
4.我发现上面这个包有的安装不了 我强行用pycharm alt+enter强行按安装的
最后附上测试代码
from pyhive import hive
import thrift
import sasl
import thrift_sasl
conn = hive.Connection(host='192.168.154.201', port=10000, database='default',auth='NOSASL')
cursor=conn.cursor()
cursor.execute('select * from a1 limit 10')
for result in cursor.fetchall():
print (result)
方法二:使用impyla库
pip install thrift-sasl==0.2.
pip install sasl
pip install impyla
测试代码如下:
from impala.dbapi import connect
conn = connect(host='192.168.154.201', port=10000, database='default')
cursor = conn.cursor()
cursor.execute('select * from a1 limit 10')
for result in cursor.fetchall():
print(result)
方法三:使用ibis库
# # 1.查询hdfs数据
from ibis import hdfs_connect
hdfs = hdfs_connect(host='xxx.xxx.xxx.xxx', port=50070)
hdfs.ls('/')
hdfs.ls('/apps/hive/warehouse/ai.db/tmp_ys_sku_season_tag')
hdfs.get('/apps/hive/warehouse/ai.db/tmp_ys_sku_season_tag/000000_0', 'parquet_dir')
# 2.查询数据到python dataframe
from ibis.impala.api import connect ImpalaClient = connect('192.168.154.201',10000,database='default')
lists=ImpalaClient.list_databases()
print(lists)
isExist=ImpalaClient.exists_table('a1') # # 执行SQL
# if(isExist):
# sql='set mapreduce.job.queuename=A'
# ImpalaClient.raw_sql(sql) # 将SQL结果导出到python dataframe
requete = ImpalaClient.sql('select * from a1 limit 10')
df = requete.execute(limit=None)
print(type(df))
print(df)
结果:

官网API:https://docs.ibis-project.org/api.html#impala-client
变成df确实能用pandas和numpy两个包能做很多事情
python操作hive 安装和测试的更多相关文章
- python操作Redis安装、支持存储类型、普通连接、连接池
一.python操作redis安装和支持存储类型 安装redis模块 pip3 install redis 二.Python操作Redis之普通连接 redis-py提供两个类Redis和Strict ...
- Linux 首先基本包安装(vim啊什么的),源,源优化,项目架构介绍, (LNMuWsgi)Django项目相关软件mysql,redies,python(相关模块)安装配置测试
内容 补充: 查看已启动服务的端口 netstat -tulnp |grep (方式1) ss -tulnp|grep (方式2) 前期铺垫: . Linux要能上网 . 掌握Linux软件包安装方法 ...
- python操作数据库-安装
首先是下载软件: 链接:http://pan.baidu.com/s/1nvp1imX 密码:6i0x 之后就是一系列设置. 安装教程:自行百度就行.需要注意的是设置my.ini时,需要加上这些东西( ...
- python操作hive并且获取查询结果scheam
执行hive -e 命令并且获取对应的select查询出来的值及其对应的scheam字段 需要在执行语句中前部添加 set hive.cli.print.header=true; 这个设置,如下语句: ...
- python3 操作 hive 安装依赖包整理
安装依赖pip install saslpip install thriftpip install thrift-saslpip install PyHive windows安装sasl报错,解决方案 ...
- Python操作Redis、Memcache、RabbitMQ、SQLAlchemy
Python操作 Redis.Memcache.RabbitMQ.SQLAlchemy redis介绍:redis是一个开源的,先进的KEY-VALUE存储,它通常被称为数据结构服务器,因为键可以包含 ...
- Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy、
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
- 文成小盆友python-num11-(2) python操作Memcache Redis
本部分主要内容: python操作memcache python操作redis 一.python 操作 memcache memcache是一套分布式的高速缓存系统,由LiveJournal的Brad ...
- 使用python操作Memcache、Redis、RabbitMQ、
Memcache 简述: Memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要 ...
随机推荐
- poj1741(入门点分治)
题目链接:https://vjudge.net/problem/POJ-1741 题意:给出一棵树,求出树上距离不超过k的点对数量. 思路:点分治经典题.先找重心作为树根,然后求出子树中所有点到重心的 ...
- TUM 慕尼黑工业大学 MSEI 课程结构介绍 ws19/20
本文内容 根据德文 tum 官网介绍:https://www.ei.tum.de/studium/master-ei-msei/ 翻译,提取并且翻译成中文信息. 本文适用于ws19/20届的学生. 概 ...
- redis发布订阅者
发布者pub.py import redis conn = redis.Redis(host='127.0.0.1', decode_responses=True) conn.publish(') 订 ...
- 【已解决】Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.
目录 问题 解决办法 备注 问题 在项目中,我们使用Spring的@Autowired注解去引入其他类时有时候阿里的编码规约插件就会提示:"Field injection is not re ...
- Collections 类和Arrays类常用方法详解
1:Collections类 max(Collection <? extends T> coll):根据元素的自然顺序,返回给定集合元素中的最大元素 min(Collection < ...
- JS基础_for循环
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Linux JDK升级
一.jdk1.4卸载 Redhat Enterprise 5 中自带安装了jdk1.4,在安装jdk1.6前,把jdk1.4卸载: 1. 首先查看系统自带的JDK版本: [root@linux ~]# ...
- vue打包后css背景图片地址找不到
背景图片变成了这样:static/css/static/imgs/xxx.jpg 解决方法,修改build/utils,添加 publicPath: '../../' 就行 对比了下,com ...
- postgres 索引
索引是一种特殊的查询表,可以使用搜索引擎的数据库以加快数据检索.简单地说,索引是表中的数据的一个指针,在一个数据库中的索引是非常相似,如:一本书的目录. 例如,如果想在一本书中引用的所有页面讨论某个话 ...
- Hadoop入门到实战全套大数据Hadoop学习视频
资料获取方式,关注公总号RaoRao1994,查看往期精彩-所有文章或者后台回复[Hadoop]获取,即可获取资源下载链接 更多资源获取,请关注公总号RaoRao1994