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)
  • 相关阅读:
    Kinect学习笔记(六)——深度数据测量技术及应用
    [device]/proc/devices and /dev/
    [Eth]Mac/Phy/mdio/Rgmii
    [uboot]uboot如何引导系统
    [网络]Linux一些网络知识
    [基础]sizeof和strlen
    [基础]关于extern指针和数组的用法
    [ucos]了解ucos
    [Linux]gcc/libc/glibc
    [i.MX6q]i.MX6q处理器,linux操作系统平台搭建 从SD卡启动系统
  • 原文地址:https://www.cnblogs.com/lexus/p/2701411.html
Copyright © 2011-2022 走看看