Reputation: 9
Can anyone please guide me in how to run .hql queries using Python. Tried Hiveutils lib but its not present in the dev environment. Any other way to execute the queries?
Upvotes: 0
Views: 12225
Reputation: 1
Getting ERROR: No matching distribution found for pyhive. Please advise
pip install pyhive
Collecting pyhive WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb688d1ab38>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pyhive/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb688d1a828>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pyhive/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb688d1a978>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pyhive/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb688d1aeb8>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pyhive/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb688d1ada0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pyhive/ ERROR: Could not find a version that satisfies the requirement pyhive (from versions: none) ERROR: No matching distribution found for pyhive
Upvotes: 0
Reputation: 2414
You can try using pyhs2, try working like the below given example
import pyhs2
with pyhs2.connect(host='localhost',
port=10000,
authMechanism="PLAIN",
user='your_user',
password='your_password',
database='your_default_db') as conn:
with conn.cursor() as cur:
print cur.getDatabases()
cur.execute("select * from table")
#Return info from query
print cur.getSchema()
Upvotes: 0
Reputation: 22952
You can use PyHive: PyHive is a collection of Python DB-API and SQLAlchemy interfaces for Presto and Hive.
Example:
from pyhive import hive
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print(cursor.fetchone())
print(cursor.fetchall())
Upvotes: 2