当前位置:
首页
文章
前端
详情

Python3通过JDBC访问非Kerberos环境的Impala

温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。

Fayson的github:

https://github.com/fayson/cdhproject

提示:代码块部分可以左右滑动查看噢

1.文档编写目的

在前面Fayson介绍了在Python2的环境下《如何使用Python Impyla客户端连接Hive和Impala》及《Python3环境通过JDBC访问非Kerberos环境的Hive》,本篇文章Fayson在Python3的环境下使用Impyla访问非Kerberos环境下的Impala以及将获取到的结果集转换为Pandas的DataFrame。

  • 本次Fayson的测试环境为

1.CM5.14.3和CDH5.14.2

2.Redhat7.4

3.Python 3.6.5

2.前置环境准备及说明

在使用Impyla访问Hive前,需要安装Python的依赖包,具体需要安装的依赖包列表如下:

sixbit_arrayimpylathriftthrift_sasl==0.2.0

(可左右滑动)

1.Python3的安装目录在/opt/cloudera/anaconda3

Python3通过JDBC访问非Kerberos环境的Impala

2.升级Python的pip版本

[root@cdh02 ~]# /opt/cloudera/anaconda3/bin/pip install --upgrade pip

(可左右滑动)

Python3通过JDBC访问非Kerberos环境的Impala

3.使用Python3的pip安装上述的依赖包

/opt/cloudera/anaconda3/bin/pip install six/opt/cloudera/anaconda3/bin/pip install bit_array/opt/cloudera/anaconda3/bin/pip install thrift/opt/cloudera/anaconda3/bin/pip install thrift_sasl==0.2.0/opt/cloudera/anaconda3/bin/pip install impyla

(可左右滑动)

Python3通过JDBC访问非Kerberos环境的Impala

Python3通过JDBC访问非Kerberos环境的Impala

Python3通过JDBC访问非Kerberos环境的Impala

3.Python3访问Hive示例代码

[root@cdh02 python_code]# vim impaly_impala.py from impala.dbapi import connectfrom impala.util import as_pandasconn = connect(host='cdh01.fayson.com',port=25004,database='default')print(conn)cursor = conn.cursor()cursor.execute('show databases')results = cursor.fetchall()print(results)cursor.execute('select * from ods_user limit 10')df = as_pandas(cursor)print(df)

(可左右滑动)

Python3通过JDBC访问非Kerberos环境的Impala

4.示例运行

在服务上使用如下命令运行Python代码

[root@cdh02 python_code]# /opt/cloudera/anaconda3/bin/python impaly_impala.py 

(可左右滑动)

Python3通过JDBC访问非Kerberos环境的Impala

5.总结

1.Impyla包既可以访问Hive也可以访问Impala,所以在使用Impyla访问Impala时也需要安装相应的依赖包。

2.在使用Impyla访问非Kerberos环境的Impala时,不需要指定user和auth_mechanism参数,否则会连接失败。

提示:代码块部分可以左右滑动查看噢

为天地立心,为生民立命,为往圣继绝学,为万世开太平。

温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。

推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。

Python3通过JDBC访问非Kerberos环境的Impala

原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操

本文分享自微信公众号 - Hadoop实操(gh_c4c535955d0f)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。