thrift for python部署

來源:互聯網
上載者:User

安裝這個是為了更方便的使用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")

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.