This is installed to make it easier to use Python to manipulate hive.
Get Thrift,
Under the Linux command:
wget http://labs.renren.com/apache-mirror/thrift/0.8.0/thrift-0.8.0.tar.gz
TAR-XVF thrift-0.8.0.tar.gz
CD thrift-0.8.0
./configure
Make
sudo make install
Then install the thrift of Python module, very simple. This command is automatically installed with the previous easy_install.
[Root@master ~]# Easy_install Thrift
Searching for Thrift
Best Match:thrift 0.8.0
Processing Thrift-0.8.0-py2.7-linux-x86_64.egg
Thrift 0.8.0 is already the active version in Easy-install.pth
Using/usr/local/lib/python2.7/site-packages/thrift-0.8.0-py2.7-linux-x86_64.egg
Processing dependencies for Thrift
Finished processing dependencies for thrift
If the root user is directly using Easy_install thrift, then sudo easy_install thrift is required for other users.
Also about Python connected to hive operation, on the official website and other blogs are related to the introduction of the operation is very simple, here is not specific examples of operations.
#!/usr/bin/env python
Import sys
Sys.path.append ('/usr/local/hive/lib/py ')
from Hive_service Import Thrifthive
from hive_service.ttypes import hiveserverexception
to thrift import Thrift
From Thrift.transport import Tsocket
from Thrift.transport import ttransport
from Thrift.protocol Import Tbinaryprotocol
def hiveexe (sql):
Try:
transport = Tsocket.tsocket (' 127.0.0.1 ', 10000)
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 ("select * from Paylog limit")