全部博文(22)
分类: Python/Ruby
2012-06-05 08:46:37
点击(此处)折叠或打开
import os,sys
from hive_service import ThritfHive
from hive_service.ttypes import HiveServerException
from thrift.transport import TSocket
from thrift import Thrift
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
if__name__=='__main__':
try:
socket = TSocket.TSocket('10.40.32.200', 10000)
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = ThriftHive.Client(protocol)
sql = 'select id, name from mydb.test'
transport.open()
client.execute(sql)
with open('/home/username/out.txt','w') as out_file:
while client.fetchOne():
out_file.write(client.fetchOne())
transport.close()
except Thrift.TException, tx:
print'%s'%(tx.message)
点击(此处)折叠或打开
[username@localhost python]$ python pre_process.py
Traceback (most recent call last):
File "pre_process.py", line 1, in
from hive_service import ThritHive
ImportError: cannot import name ThritHive
点击(此处)折叠或打开
sudo cp -r lib/* /usr/lib/python2.7/site-packages/