我正在尝试将安全配置单元服务器连接到 thrift
应用程序编程接口。如果hiveserver不需要身份验证(不安全),但不适用于安全的hiveserver,则此代码可以很好地工作
参考https://cwiki.apache.org/confluence/display/hive/hiveclient
# !/usr/bin/env python
import sys
from hive import ThriftHive
from hive.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
try:
transport = TSocket.TSocket('localhost', 10000)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = ThriftHive.Client(protocol)
transport.open()
client.execute("CREATE TABLE r(a STRING, b INT, c DOUBLE)")
client.execute("LOAD TABLE LOCAL INPATH '/path' INTO TABLE r")
client.execute("SELECT * FROM r")
while (1):
row = client.fetchOne()
if (row == None):
break
print row
client.execute("SELECT * FROM r")
print client.fetchAll()
transport.close()
except Thrift.TException, tx:
print '%s' % (tx.message)
1条答案
按热度按时间cwdobuhd1#
您需要在代码中添加身份验证机制,如“nosal”、“kerberos”、“ldap”等,并根据该机制提供适当的凭据。
例子:
参考文献:https://github.com/bradruderman/pyhs2/blob/master/pyhs2/connections.py