How to access hive using Python (Source code )

Use case : If you want to do some scheduling or some automation , we may need to access Hive using Python. 

Libraries used : impyla  (https://github.com/cloudera/impyla) 
Python version used : 3.6
Here our environment is AWS EMR with preconfigured

#Source Code - Python
#Code by www.Freshers.in
#For Learning purpose
#Python Hive
from impala.dbapi import connect
conn = connect(host='10.18.179.231', port=10000, auth_mechanism='PLAIN')
cur = conn.cursor()
cur.execute("show databases")
dbs = cur.fetchall()
for db in dbs:
    print(db)

If you face any issue like “bitarray-1.6.1-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.” 

You may need to install one of the bellow based on your windows.

For 64 bit 
pip install https://download.lfd.uci.edu/pythonlibs/w4tscw6k/cp36/bitarray-1.6.1-cp36-cp36m-win_amd64.wh

For 32 bit
pip install https://download.lfd.uci.edu/pythonlibs/w4tscw6k/cp36/bitarray-1.6.1-cp36-cp36m-win32.whl

 

Author: user

Leave a Reply

Your email address will not be published. Required fields are marked *