Reputation: 69
I have tried various approach of using hive with python.
One is
How to Access Hive via Python?
Also tried https://sites.google.com/site/tingyusz/home/blogs/hiveinpython
Where I am getting
File "py_hive.py", line 8, in <module>
database='default') as conn:
File "/home/karimk/python/lib/python2.7/site-packages/pyhs2/__init__.py", line 7, in connect
return Connection(*args, **kwargs)
File "/home/karimk/python/lib/python2.7/site-packages/pyhs2/connections.py", line 52, in __init__
cur.execute(query)
File "/home/karimk/python/lib/python2.7/site-packages/pyhs2/cursor.py", line 61, in execute
res = self.client.ExecuteStatement(query)
File "/home/karimk/python/lib/python2.7/site-packages/pyhs2/TCLIService/TCLIService.py", line 244, in ExecuteStatement
return self.recv_ExecuteStatement()
File "/home/karimk/python/lib/python2.7/site-packages/pyhs2/TCLIService/TCLIService.py", line 260, in recv_ExecuteStatement
raise x
thrift.Thrift.TApplicationException: Required field 'sessionHandle' is unset! Struct:TExecuteStatementReq(sessionHandle:null, statement:USE default, confOverlay:{})
Python code:
import pyhs2
with pyhs2.connect(host='dmeet-master02.inetuhosted.net',
port=10000,
authMechanism="PLAIN",
user='userk',
password='userk',
database='default') as conn:
with conn.cursor() as cur:
#Show databases
print cur.getDatabases()
#Execute query
cur.execute("select * from table")
#Return column info from query
print cur.getSchema()
#Fetch table results
for i in cur.fetch():
print i
break
any hint on this?
Upvotes: 3
Views: 2754
Reputation: 1333
I am using a similar initialization code for connecting with Hive and it works for me.
But, I can see that it's failing to initialize the connection. The field sessionHandle is set internally while opening connection with the server. It is unset (or set to None) when corresponding socket connection can't be opened. Try reaching without specifying a database and see if it works.
Upvotes: 1