#! /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 = '2017. 0.0.1'
Hive_server_port = 10000
# Hive_ SQL = 'select count (*) from ssp_factbids'
Hive_ SQL = "select count (*) from ssp_factbids where logdate_id = '20140901 '"
Def hiveExe (SQL ):
Try:
Transport = TSocket. TSocket (hive_server_ip, hive_server_port)
Transport = TTransport. TBufferedTransport (transport)
Protocol = TBinaryProtocol. TBinaryProtocol (transport)
Client = thrithive. Client (protocol)
Transport. open ()
Client.exe cute (SQL)
Print "The return value is :"
Print client. fetchAll ()
Print "............"
Transport. close ()
Setting t Thrift. TException, tx:
Print '% s' % (tx. message)
If _ name _ = '_ main __':
HiveExe (hive_ SQL)