python远程访问hive
#!/usr/bin/python
import sys
sys.path.append('/home/zhoujie/downloads/hive-0.7.0-cdh3u0/lib/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
hive_server_ip='127.0.0.1'
hive_server_port=10000
#hive_sql='select count(*) from ssp_factbids'
hive_sql="select count(*) from ssp_factbids where logdate_id='20121101'"
def hiveexe(sql):
try:
transport = tsocket.tsocket(hive_server_ip, hive_server_port)
transport = ttransport.tbufferedtransport(transport)
protocol = tbinaryprotocol.tbinaryprotocol(transport)
client = thrifthive.client(protocol)
transport.open()
client.execute(sql)
print "the return value is : "
print client.fetchall()
print "............"
transport.close()
except thrift.texception, tx:
print '%s' % (tx.message)
if __name__ == '__main__':
hiveexe(hive_sql)