hive python thrift client
#!/usr/bin/env python
#coding:utf-8
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages/py")
from hive_service import ThriftHive
from hive_service.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
ip = '192.168.0.176'
port = 10000
#sql = "show tables"
sql = "select count(0) from test_table"
def hiveExe(sql):
transport = None
try:
transport = TSocket.TSocket( ip , port )
transport = TTransport.TBufferedTransport( transport )
protocol = TBinaryProtocol.TBinaryProtocol( transport )
client = ThriftHive.Client( protocol )
transport.open()
print "execute sql : %s \n" % sql
client.execute( sql )
print "The return value is : \n"
print client.fetchAll()
print "\n......"
transport.close()
except Thrift.TException,tx:
print '%s' % tx.message
finally:
if transport != None :
transport.close()
if __name__ == '__main__':
hiveExe(sql) 相关推荐
Runtimeclass 2020-10-20
Martian 2020-10-13
jerry00 2020-06-11
infoscienceliu 2020-02-01
风之翊 2019-12-29
XiaoqiangNan 2020-01-08
jerry00 2020-01-08
Ggaomiss 2019-12-14
程序媛菜鸟 2019-11-19
jerry00 2019-11-19
lvwenyuan 2019-11-18
infoscienceliu 2019-11-17
hyclq 2015-05-17
XiaoqiangNan 2015-08-18
infoscienceliu 2019-11-09
Martian 2019-11-08
XiaoqiangNan 2019-11-04
AReallyMan 2019-07-13