我尝试过使用python的hive的各种方法。
一个是
How to Access Hive via Python?
还尝试了https://sites.google.com/site/tingyusz/home/blogs/hiveinpython
我在哪里
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代码:
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
对此有什么暗示?
答案 0 :(得分:1)
我使用类似的初始化代码与Hive连接,它对我有用。
但是,我可以看到它未能初始化连接。 字段 sessionHandle 在打开与服务器的连接时在内部设置。当无法打开相应的套接字连接时,它是未设置(或设置为无)。尝试在不指定数据库的情况下到达并查看它是否有效。