Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the Python Impyla client to connect Hive and Impala

Shulou Source: shulou.com Published: 2022-06-01 15:42:38 09月25日 Update

This article mainly introduces how to use the Python Impyla client to connect Hive and Impala, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Use the hive module

Pip install sasl

Pip install thrift

Pip install thrift-sasl

Pip install PyHive

[root@ip-172-31-40-242b] # more testpyhive.py

From pyhive import hive

Conn = hive.Connection (host='xxxxxxx', port=10000, database='collection',username='')

Cursor=conn.cursor ()

Cursor.execute ('select * from tb_partition limit 10')

For result in cursor.fetchall ():

Print result

[root@ip-172-31-40-242b] # python testpyhive.py

(upright 1, upright 2, upright 201707')

(upright 1, upright 2, upright 201707')

(upright 123, None, upright 201709')

(upright 123, upright 456, ugg 201709')

(upright 45678, upright 456, upright 201709')

(upright 123, None, upright 201709')

(upright 123, upright 456, ugg 201709')

(upright 45678, upright 456, upright 201709')

(upright 123, None, upright 201709')

(upright 123, upright 456, ugg 201709')

Official API: https://pypi.org/project/PyHive/

How to use Python Impyla client to connect Hive and Impala#-*-coding:utf-8-*-from impala.dbapi import connectconn = connect (host='172.31.46.109',port=10000,database='collection',auth_mechanism='PLAIN') print (conn) cursor = conn.cursor () # param =''SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;SET hive.support.concurrency=true '' cursor.execute (param) cursor.execute ('SELECT uid FROM redefine_collection where uid=4028 limit 10') print cursor.description # prints the result set's schemaresults = cursor.fetchall () print results## Python connection Impala (ImpalaTest.py) # # from impala.dbapi importconnect## conn = connect (host='ip-172-31-26-80. APL southeastMI 1.compute.calculation' Port=21050) # # print (conn) # # cursor = conn.cursor () # cursor.execute ('show databases') # # print cursor.description # prints the result set's schema## results = cursor.fetchall () # print (results) # # cursor.execute (' SELECT * FROM test limit 10') # # print cursor.description # prints the result set's schema## results = cursor.fetchall () # # print (results) Thank you for reading this article carefully I hope the article "how to use Python Impyla client to connect Hive and Impala" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles customers clients value interests at the same time official more friends modules knowledge editing industry information information channels channels utf-8 reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple vpn MariaDB NVidia