zoukankan      html  css  js  c++  java
  • 用python写hiveclient 改善 ITeye技术网站

    用python写hiveclient - 改善 - ITeye技术网站


    第一步:

    hive-0.7.0\lib\py 中所有py文件拷贝到你自己的Python工程中。

    第二步:

    把下面的代码拷贝一份新建一个py文件,修改IP,port ,输入要执行的SQL。

    Python代码  收藏代码
    1. #encoding=utf-8  
    2. from hive_service import ThriftHive  
    3. from hive_service.ttypes import HiveServerException  
    4. from thrift import Thrift  
    5. from thrift.transport import TSocket  
    6. from thrift.transport import TTransport  
    7. from thrift.protocol import TBinaryProtocol  
    8.   
    9. def hiveExe(sql):  
    10.     try:  
    11.         transport = TSocket.TSocket('119.188.7.xx'10000)   
    12.         transport = TTransport.TBufferedTransport(transport)  
    13.         protocol = TBinaryProtocol.TBinaryProtocol(transport)  
    14.         client = ThriftHive.Client(protocol)  
    15.         transport.open()  
    16.   
    17.         client.execute(sql)  
    18.   
    19.         print "The return value is : "   
    20.         print client.fetchOne()  
    21.         print "............"  
    22.     except Thrift.TException, tx:  
    23.         print '%s' % (tx.message)  
    24.     finally:  
    25.         transport.close()  
    26.   
    27. if __name__ == '__main__':  
    28.     hiveExe("select count(*) from pokes")  

     第三步:


    hive --service hiveserver (启动hive server)
  • 相关阅读:
    PHP 上传文件限制
    vim设置golang语法高亮 (Centos)
    linux下安装配置go语言环境
    Vim升华之树形目录插件NERDTree安装图解(ubuntu)
    linux下配置Node.js环境
    RabbitMQ的使用(二)- RabbitMQ服务在单机中做集群
    RabbitMQ的使用(一)- RabbitMQ服务安装
    Exceptionless(二)
    Exceptionless
    SQL Server2012如何打开2016的profiler文件
  • 原文地址:https://www.cnblogs.com/lexus/p/2701411.html
Copyright © 2011-2022 走看看