用python程序连接hive
2012-09-10 09:28:20 来源:我爱运维网 评论:0 点击:
客户机:10.10.20.20:
注: 本机器安装了thrift for python, 详细参考: http://thrift.apache.
Hadoop集群的Hive服务器:10.10.20.101
用python程序连接hive测试程序如下:
[root@10.10.20.20 ~]# cat test_hive.py
#!/usr/bin/env python
import sys
sys.path.append('/home/pplive/
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('10.10.20.101', 10000)
transport = TTransport.TBufferedTransport(
protocol = TBinaryProtocol.
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 p2pcdn_log limit 1")
上一篇:有用的Nginx日志分析awk脚本
下一篇:最后一页
评论排行
- ·雅虎前员工给新CEO的10条建议(1)