温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2021-12-13 17:57:56 来源:亿速云 阅读:259 作者:小新 栏目:大数据

这篇文章将为大家详细讲解有关Python3如何通过JDBC访问非Kerberos环境的Impala,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。


1.测试环境

1.CM5.14.3和CDH5.14.2

2.Redhat7.4

3.Python 3.6.5

2.前置环境准备及说明


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

six
bit_array
impyla
thrift
thrift_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 connect
from impala.util import as_pandas
conn = 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

关于“Python3如何通过JDBC访问非Kerberos环境的Impala”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI