首页 > 编程语言 > 详细

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

时间:2021-07-23 23:34:44      阅读:13      评论:0      收藏:0      [点我收藏+]

代码如下

#!/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)

https://www.jb51.cc/python/526858.html

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

原文:https://www.cnblogs.com/hellow-gu/p/15049908.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!