Python3 impyla 连接 hiveserver2
简介:
接到一个任务,需要从 hive 中读取数据,生成报表。
官方文档提供了一个使用 pyhs2 连接 hive 的例子,这本来很好的嘛。
结果去 Github:https://github.com/BradRuderman/pyhs2 瞅了一眼,很遗憾 pyhs2 项目已经不维护了。
不过,提供了两个很不错的替代项目:https://github.com/cloudera/impyla、https://github.com/dropbox/PyHive
终于绕到今天的主角了~
一、HiveServer2
shell > cd /usr/local/apache-hive-2.3.-bin shell > sh bin/hiveserver2 start > logs/beeline.log >& & # 这就启动了,停止的话好像必须 kill pid。
二、impyla
# 安装依赖
shell > yum -y install gcc gcc-c++ cyrus-sasl-devel cyrus-sasl-plain # 创建虚拟环境
shell > virtualenv --no-site-packages -p python3 venv # 启用虚拟环境
shelll > source venv/bin/activate (venv) shell > python -V
Python 3.6. # 安装 impyla 及所需依赖包
(venv) shell > pip install ipython six bit_array thriftpy thrift_sasl==0.2. sasl impyla (venv) shell > ipython In []: from impala.dbapi import connect In []: conn = connect(host="192.168.10.45", port=, database="logsdb", auth_mechanism="PLAIN") In []: cur = conn.cursor() In []: cur.execute("select count(*) from log_bftv_api") In []: cur.fetchone()
Out[]: (,) In []: conn.close() # 程序查出了 hive table log_bftv_api 中总共有 条数据。 # 其中,连接配置中 auth_mechanism 的值由 hive-site.xml 配置文件中 hive.server2.authentication 配置项指定。 # PLAIN 代表不启用认证,也就是 hive.server2.authentication 的默认值:NONE。
Python3 impyla 连接 hiveserver2的更多相关文章
- Python3实现连接SQLite数据库的方法
本文实例讲述了Python3实现连接SQLite数据库的方法,对于Python的学习有不错的参考借鉴价值.分享给大家供大家参考之用.具体方法如下: 实例代码如下: ? 1 2 3 4 5 6 7 8 ...
- 由“Beeline连接HiveServer2后如何使用指定的队列(Yarn)运行Hive SQL语句”引发的一系列思考
背景 我们使用的HiveServer2的版本为0.13.1-cdh5.3.2,目前的任务使用Hive SQL构建,分为两种类型:手动任务(临时分析需求).调度任务(常规分析需求),两者均通过我们的 ...
- python3.5连接oracle数据及数据查询
今天心血来潮研究下用python连接oracle数据库,看了一下demo,本以为很简单,从操作到成功还是有点坎坷,这里分享给大家,希望为后面学习的童鞋铺路. 一.首先按照cx_Oracle 二:在py ...
- 用Java代码通过JDBC连接Hiveserver2
1.在终端启动hiveserver2#hiveserver2 2.使用beeline连接hive另外打开一个终端,输入如下命令(xavierdb必须是已经存在的数据库)#beeline -u jdbc ...
- 【原创】大叔经验分享(38)beeline连接hiveserver2报错impersonate
beeline连接hiveserver2报错 Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost: ...
- python3.4连接mysql5.7数据库增删改查
#!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...
- 通过JDBC连接HiveServer2
如果通过JDBC连接HiveServer2时提示:User: hive is not allowed to impersonate hive,需要在core-site.xml中新增如下配置: hado ...
- python3.4连接mysql数据库的方法
python3.4连接mysql数据库的方法 发布时间:2014-08-04编辑:www.jbxue.com 本文介绍了python3.4连接mysql数据库的方法,在python3.4中不能用mys ...
- python3.6 连接mysql数据库问题
最近有个项目欲安装MySQL-python/1.2.5一直失败. 环境: win7 python3.6.2 报错信息如下: Creating library build\temp.win32-3.6\ ...
随机推荐
- php curl curl_getinfo()返回参数详解
php curl请求在curl_exec()函数执行之后,可以使用curl_getinfo()函数获取CURL请求输出的相关信息,示例代码如下: curl_exec($ch);$info = curl ...
- FineUI 单击菜单页面内容完全刷新,关闭Tab
res/js/main.js 修改initTreeabStrip 中 refreshWhenExist.refreshWhenTabChang两参数值 // 初始化主框架中的树(或者Accor ...
- bzoj 4025 二分图——线段树分治+LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4025 线段树分治,用 LCT 维护链的长度即可.不过很慢. 正常(更快)的方法应该是线段树分 ...
- Hadoop集群搭建笔记
1.安装虚拟机 VMware workstation CentOS 镜像 安装Linux虚拟机:(在Win7上) 1)安装VMwareWorkstations(可修改配置) 2)添加CentOS镜像( ...
- 【appium】根据class_name定位元素
目前没有尝试成功,等成功后补充 class_name=class可以通过UIAutomatorViewer获得.
- java 异常和异常处理Exception
Java Exception: 1.Error 2.Runtime Exception 运行时异常3.Exception 4.throw 用户自定义异常 异常类分两大类型:Error类代表了编译和系统 ...
- UDP丢包问题
1. 问题描述 PC-A向PC-B发送UDP packet(共16K bytes),如果B机木有及时Read,UDP包将大量丢失. 2. 原因及解决 因为B木有及时接收,socket缓冲区放不下了. ...
- 几个有用的Linux命令
原文:http://spin.atomicobject.com/2013/09/09/5-unix-commands/ 本文为原文摘要. 1. man ascii 打印ascii代码表 2. cal ...
- 开发框架-APP:Hybird App
ylbtech-开发框架-APP:Hybird App Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app,兼具“Native App良好用户交互体 ...
- mysql binlog协议分析--具体event
这几天在修改canal, 连接mysql和maria接收到的event有所区别 拿一个简单的insert sql来举例 mysql 会有以下几个event写入到binlog里 1.ANONYMOUS_ ...