当前位置: 移动技术网 > IT编程>脚本编程>Python > python远程访问hive

python远程访问hive

2019年04月05日  | 移动技术网IT编程  | 我要评论

月亮看盘,分身情人简谱,邯郸有职招聘网

#!/usr/bin/python
import sys
sys.path.append('/home/zhoujie/downloads/hive-0.7.0-cdh3u0/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


hive_server_ip='127.0.0.1'
hive_server_port=10000
#hive_sql='select count(*) from ssp_factbids'
hive_sql="select count(*) from ssp_factbids where logdate_id='20121101'"


def hiveexe(sql):
    try:
        transport = tsocket.tsocket(hive_server_ip, hive_server_port)
        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(hive_sql)
 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网