#!/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)
Python Remote Access Hive