新西兰服务器

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


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

发布时间:2021-12-13 17:57:56 来源:高防服务器网 阅读:85 作者:小新 栏目:大数据

这篇文章将为大家详细讲解有关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

2.升级Python的pip版本

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

(可左右滑动)

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

(可左右滑动)

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)

(可左右滑动)

4.示例运行


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

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

(可左右滑动)

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

[微信提示:高防服务器能助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

[图文来源于网络,不代表本站立场,如有侵权,请联系高防服务器网删除]
[