thrift for python部署<转>

安装这个是为了更方便的使用python操作hive。

获取thrift,

在linux命令下:

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

 

然后再安装thrift of python 模块,很简单。用之前的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

 

如果是root用户就直接用easy_install thrift,如果是其他用户的话需要sudo easy_install thrift。

另外关于python连接到hive的操作,在官方网站上和其他的博客里都有相关的介绍操作也很简单,这里就不具体举例操作了。


#!/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
from 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 10")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值