zoukankan      html  css  js  c++  java
  • HiveClient

    HiveClient

    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)
  • 相关阅读:
    django之form表单验证
    django之分页器
    django之Ajax
    django之模型层
    django之模板语法
    django之视图函数
    mysql 数据类型
    mysql 命令行查看数据库、创建数据库、选择数据库、删除数据库
    java里的日期时间
    Arrays类
  • 原文地址:https://www.cnblogs.com/lexus/p/2872285.html
Copyright © 2011-2022 走看看