python 访问 hive2
来源:互联网 发布:linux输入法 编辑:程序博客网 时间:2024/05/24 23:14
HiveServer2为客户端在远程执行hive查询提供了接口,通过Thrift RPC来实现,还提供了多用户并发和认证功能。目前使用python的用户可以通过pyhs2这个模块来连接HiveServer2,实现查询和取回结果的操作。
hive_client.py
#!/usr/bin/env python#coding:utf-8import pyhs2''' hive client'''class HiveClient: ''' docstring for HiveClient ''' def __init__(self, db_host, user, password, database, port=10000, authMechanism="PLAIN"): 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 queryNoResult(self,sql): ''' query no result ''' with self.conn.cursor() as cursor: cursor.execute(sql) def close(self): ''' close connection ''' self.conn.close()
hive_conf.py
#!/usr/bin/env python#coding:utf-8import sysimport osclass HiveConnAttribute: def getHost(self): return '**' def getUser(self): return '**' def getPasswd(self): return '**' def getDatabase(self): return '**' def getPort(self): return 10000 def getAuthMechanism(self): return 'PLAIN'
query.py
#!/usr/bin/env python#coding:utf-8from hive_client import HiveClientfrom hive_conf import HiveConnAttributeif __name__ == '__main__': hiveConn = HiveConnAttribute() hiveHost = hiveConn.getHost() hiveUser = hiveConn.getUser() hivePasswd = hiveConn.getPasswd() hiveDatabase = hiveConn.getDatabase() hivePort = hiveConn.getPort() hiveAuthMechanism = hiveConn.getAuthMechanism() hive_client = HiveClient(db_host = hiveHost, port = hivePort, user = hiveUser, password = hivePasswd, database = hiveDatabase, authMechanism=hiveAuthMechanism) hql = '''.........''' hive_client.query(hql) hive_client.queryNoResult(hql) hive_client.close()
阅读全文
0 0
- python 访问 hive2
- python访问hive2
- centos7下python连接 hive2
- hive2
- spark 2.1.1访问hive2.3.0
- hive2安装
- hive2:HIVE的结构
- 一步一步安装hive2,beeline
- java jdbc连接hive2
- hive2.0.0安装
- 使用java操作hive2
- Hive2 beeline 使用方法
- hive2 自定义验证登录
- hive2.1.0配置hwi
- Hive2.1.0安装配置
- hive2.1.0安装部署
- hive2.1安装
- Hive2.0.0安装配置
- 巧用margin/padding的百分比值实现高度自适应(
- Java菜鸟教程 插入排序初步和几个有趣的练习
- unity3D 长按Button使button失效点击事件
- Tomcat容器的最大并发数
- 新手关于跌倒器iterator中next()方法的思考
- python 访问 hive2
- java语言中垃圾回收的优点和原理
- SparkR初体验
- LINK : warning C4727 分析
- JAVA开发的23种设计模式之 --- 备忘录模式
- HTTP Keep-Alive 讲解
- 7-7 字符串替换
- HDU 4841 圆桌问题 (vector模拟)
- linux scp拷贝文件,跳过“yes/no”