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)
  • 相关阅读:
    activiti实战系列之动态表单 formService 自定义变量类型
    js向一个数组中插入元素的几个方法-性能比较
    Mac系统安装和配置tomcat步骤详解
    Spring注解之@validated的使用
    Spring注解之@Lazy注解
    centos命令行系列之升级glibc到
    docker实战系列之docker 端口映射错误解决方法
    centos命令行系列之centos6防火墙的关闭以及开启
    docker实战系列之搭建rabbitmq
    运营型模型
  • 原文地址:https://www.cnblogs.com/lexus/p/2701411.html
Copyright © 2011-2022 走看看