PyHive(遇到的坑)以及一些ETl使用函数
发布日期:2022-02-27 02:38:02
浏览次数:43
分类:技术文章
本文共 3004 字,大约阅读时间需要 10 分钟。
TEL操作使用函数:
截取出一个字段中的数字部分select taskId,regexp_extract(regCapital,'([a-zA-Z0-9]+)',1) from test001;
使用函数过滤将*号替换(hive中没有replace函数)
select regexp_replace(businessscope,'*','') from test003;
环境准备:
Anaconda整合python(用的3.7版本) 有两种方式: 基于pyhive连接hive。 基于impyla连接hive。 基于pyhive安装依赖包(注意:sasl没有下载成功开始是缺少c++包 自己在网上下载的)pip install saslpip install thriftpip install thrift-saslpip install PyHive
pyhive连接代码:
from pyhive import hiveconn = hive.Connection(host='192.168.2.200', port=10000, username='www', database='xcc_company_name', auth="NOSASL")cursor = conn.cursor()cursor.execute('select businessscope from ods_basic_infor limit 20')
报错整理:
执行上面代码会报出如下错误:
Traceback (most recent call last): File "D:/satori/1.py", line 14, inconn = connect(host='47.94.174.89', port=10000, database="default", auth_mechanism='PLAIN') File "C:\python38\lib\site-packages\impala\dbapi.py", line 144, in connect service = hs2.connect(host=host, port=port, File "C:\python38\lib\site-packages\impala\hiveserver2.py", line 825, in connect transport.open() File "C:\python38\lib\site-packages\thrift_sasl\__init__.py", line 75, in open self._send_message(self.START, chosen_mech) File "C:\python38\lib\site-packages\thrift_sasl\__init__.py", line 94, in _send_message self._trans.write(header + body)TypeError: can't concat str to bytes
根据提示信息:我们进入thrift_sasl模块下的__init__.py中,找到85行
值得一提的是,python中的缩进应该是四个空格,但是thrift_sasl用的两个空格,不过不影响
def _send_message(self, status, body): header = struct.pack(">BI", status, len(body)) self._trans.write(header + body) self._trans.flush() # 我们看到报错的原因是header + body、因为字符串和字节无法相加 # 将上面代码改成如下def _send_message(self, status, body): header = struct.pack(">BI", status, len(body)) if isinstance(body, str): body = bytes(body, encoding="utf-8") self._trans.write(header + body) self._trans.flush()
执行的时候会报出如下错误
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'
在linux上可以通过yum install cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi解决
这是sasl不支持Windows机型所导致的,我们可以将auth改成NOSASL
from pyhive import hiveconn = hive.Connection(host='47.94.174.89', port=10000, database='default', auth="NOSASL")cursor = conn.cursor()cursor.execute('select * from girls')print(cursor.fetchall())
但是这样又会报出如下错误
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
需要同时要求,hive的hive-site.xml中增加如下配置
hive.server2.authentication NOSASL
将hive中的认证给修改掉,所以才说Windows上使用pyhive的局限性非常大,因为它要求服务器上的hive不能使用认证,但是服务器上的hive一般都是使用Kerberos认证的。
更改Kerberos认证之后对hiveservice2连接的更改
进入beeline之后使用它连接
!connect jdbc:hive2://127.0.0.1:10000/default/;auth=noSasl
在hive-site.xml中添加(对于spark整合hive还没有通)
更改Kerberos认证之后对kettle连接hive2的更改
需要更改配置core-site.xmlkettle的设置修改如下:需要在数据库的名称后面添加;auth=noSasl
总结pyhive的安装参考链接
https://www.cnblogs.com/traditional/p/12534719.html转载地址:https://blog.csdn.net/weixin_43401381/article/details/106649821 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年03月07日 12时42分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
html图片水平居中,CSS制作图片水平垂直居中
2019-04-21
水滴pin安卓版apk_财务报销管理系统
2019-04-21
平面设计师okr_设计团队的KPI/OKR如何制定?
2019-04-21
仪表盘故障图像识别_仪表显示的图像识别算法研究
2019-04-21
c#背单词小程序视频_C#用timer实现背单词小程序
2019-04-21
24v开关电源维修技巧_【电视技术】液晶电视电源板十个维修经验分享
2019-04-21
bash 不是内部或外部命令_python学习笔记6-pip命令不是内部命令问题
2019-04-21
mysql无法写数据库_求助,为何我的数据不能写入数据库
2019-04-21
ssh 两个mysql数据库_ssh连接两个数据库(转)
2019-04-21
mysql 双向链表_23张图!万字详解「链表」,从小白到大佬!
2019-04-21
mysql 常量命名规则_详解Java编程规约(命名风格、常量定义、代码格式)
2019-04-21
pomelo mysql_全文索引 - Pomelo.EFCore.MySql
2019-04-21
rtsp 华为_华为多实例生成树RSTP配置详解
2019-04-21
php不需要也能输出,php 如何只输出最后生成的那个值??
2019-04-21
php正则过滤sql关键字,使用正则表达式屏蔽关键字的方法
2019-04-21
php取整v,php取整方式分享
2019-04-21