Thrift for Python deployment

Source: Internet
Author: User

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")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.