HiveClient - Apache Hive - Apache Software F

系统 3330 0

HiveClient - Apache Hive - Apache Software Foundation

Python

Operates only on a standalone server. Set (and export) PYTHONPATH to build/dist/lib/py.

The python modules imported in the code below are generated by building hive.

Please note that the generated python module names have changed in hive trunk.

          #!/usr/bin/env python


          
            import
          
           sys

from hive 
          
            import
          
           ThriftHive
from hive.ttypes 
          
            import
          
           HiveServerException
from thrift 
          
            import
          
           Thrift
from thrift.transport 
          
            import
          
           TSocket
from thrift.transport 
          
            import
          
           TTransport
from thrift.protocol 
          
            import
          
           TBinaryProtocol


          
            try
          
          :
    transport = TSocket.TSocket('localhost', 10000)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    client = ThriftHive.Client(protocol)
    transport.open()

    client.execute(
          
            "CREATE TABLE r(a STRING, b INT, c DOUBLE)"
          
          )
    client.execute(
          
            "LOAD TABLE LOCAL INPATH '/path' INTO TABLE r"
          
          )
    client.execute(
          
            "SELECT * FROM r"
          
          )
    
          
            while
          
           (1):
      row = client.fetchOne()
      
          
            if
          
           (row == None):
        
          
            break
          
          
      print row
    client.execute(
          
            "SELECT * FROM r"
          
          )
    print client.fetchAll()

    transport.close()

except Thrift.TException, tx:
    print '%s' % (tx.message)
        

HiveClient - Apache Hive - Apache Software Foundation


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论