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)
  • 相关阅读:
    将博客搬至CSDN
    defender 月考总结
    生日祝福@陈俊翰
    个性签名
    你这是virus吧?
    (CPSCA's)CPOJC+VIJOS
    Sentence by defender
    工作制一览
    最长上升子序列
    mysql约束
  • 原文地址:https://www.cnblogs.com/lexus/p/2701411.html
Copyright © 2011-2022 走看看