博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python访问hive
阅读量:7309 次
发布时间:2019-06-30

本文共 2053 字,大约阅读时间需要 6 分钟。

#!/usr/bin/env python# -*- coding: utf-8 -*-# hive util with hive server2"""@author:@create:"""__author__ = 'knktc'__version__ = '0.1'import pyhs2class HiveClient:    def __init__(self, db_host, user, password, database, port=10000, authMechanism="PLAIN"):        """        create connection to hive server2        """        self.conn = pyhs2.connect(host=db_host,                                  port=port,                                  authMechanism=authMechanism,                                  user=user,                                  password=password,                                  database=database                                  )    def query(self, sql):        """        query        """        with self.conn.cursor() as cursor:            cursor.execute(sql)            return cursor.fetch()    def close(self):        """        close connection        """        self.conn.close()def main():    """    main process    @rtype:    @return:    @note:    """    hive_client = HiveClient(db_host='127.0.0.1', port=10086, user='', password='',                            database='db', authMechanism='PLAIN')    print hive_cient.getDatabases()    result = hive_client.query("select * from test_db t where t.dt = '2017-03-01' limit 1")    print result    hive_client.close()if __name__ == '__main__':    main()

  

 

windows下32位没成功,报错(64位可以http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载 

File "build\bdist.win32\egg\pyhs2\cloudera\thrift_sasl.py", line 66, in openthrift.transport.TTransport.TTransportException: Could not start SASL: Error insasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callba
python -m pip install -U pippython -m pip install pyOpenSSLhttps://pypi.python.org/pypi/pyhs2python -m pip install saslhttp://aka.ms/vcpython27python -m pip install sasl-0.2.1-cp27-cp27m-win32.whlpython -m pip install thrift-0.10.0-cp27-cp27m-win32.whl

linux安装

pyhs2,cyrus-sasl(cyrus-sasl-plain  cyrus-sasl-devel  cyrus-sasl-gssapi),gcc,libxml2-devel,libxslt-devel

 

转载于:https://www.cnblogs.com/linn/p/6526894.html

你可能感兴趣的文章
HTML5 & CSS3初学者指南(3) – HTML5新特性
查看>>
高性能Web服务器nginx
查看>>
给萌新的Flexbox简易入门教程
查看>>
『中级篇』Kubenetes简介(60)
查看>>
Java对象的序列化与反序列化
查看>>
eclipse快捷键整理
查看>>
vue.js 组件数据传递
查看>>
PHP常用数组函数小结
查看>>
lnmp平台的简单基础搭建
查看>>
链接器的应用(八)
查看>>
安卓手机上 K 歌,声音延迟怎么解决?
查看>>
cobbler批量化安装系统-CentOS7
查看>>
1周4次课 单用户模式,救援模式,克隆虚拟机,linux相互登录
查看>>
16.1 Tomcat介绍 16.2 安装jdk 16.3 安装Tomcat
查看>>
用Xshell连接VMware虚拟机
查看>>
Oracle的DDL语句不能回滚(直接提交)
查看>>
http,状态码集
查看>>
Redis设计思路学习与总结
查看>>
带你脱离视频测试的坑
查看>>
linux
查看>>