• python 访问hive


    1、安装

    pip install impyla==0.14.1
    pip install pure_sasl==0.5.1
    pip install thriftpy==0.3.9
    pip install thrift-sasl==0.2.1 
    pip install thrift
    pip install bitarray

    1、报错:thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol 'c'
       解决:
       将 C:Python27Libsite-packages hriftpyparserparser.py , line 488
       if url_scheme == '':
       改为:
       if len(url_scheme) <= 1:
    2、报错:TypeError: can't concat str to bytes
       定位到错误的最后一条,在init.py第94行(标黄的部分)
       header = struct.pack(">BI", status, len(body))
       #按照网上的提供的办法增加对BODY的处理
       if (type(body) is str):
           body = body.encode()
       self._trans.write(header + body)
       self._trans.flush()

    2、使用

    import impala.dbapi as ipdb
    
    class HiveControl:
        def __init__(self, db_name='default'):
            self.conn = ipdb.connect(host='192.168.XX.XX', port=10000, database=db_name,  user='user', password='password',
    auth_mechanism='PLAIN') self.cursor = self.conn.cursor() # 默认为NONE,另外还可以为’NOSASL’, ‘PLAIN’, ‘KERBEROS’, ‘LDAP’, ‘CUSTOM’. def excuteSql(self, sql): try: self.cursor.execute(sql) res = self.cursor.fetchall() except Exception as e: self.cursor.close() self.conn.close() raise (e) self.cursor.close() self.conn.close() return res hiv = HiveControl() print(hiv.excuteSql('show databases'))
  • 相关阅读:
    瀑布流事件
    js 面向对象 模拟日历
    leetcode 戳气球
    leetcode 地下城游戏
    laravel服务容器
    lru缓存策略
    php实现7种常见排序
    curl请求中http头的几种格式
    wireshark过滤规则(两年前记录在qq空间的日志)
    screen和nohub及&用法
  • 原文地址:https://www.cnblogs.com/snailgirl/p/13647713.html
Copyright © 2020-2023  润新知