Python通过pythony连接Hive执行Hql的脚本

前端之家收集整理的这篇文章主要介绍了Python通过pythony连接Hive执行Hql的脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣Python通过pythony连接Hive执行Hql的脚本的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。<br>
#!/usr/bin/env python
import sys
sys.path.append('/home/spark/opt/hive-1.2.1/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__':
    select_sql="select url_current from yemao1_log limit 100";
    hiveExe(select_sql)

猜你在找的Python相关文章