python-pyhs2
2024-09-05 10:58:32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# hive util with hive server2
"""
@author:
@create:
"""
__author__ = 'knktc'
__version__ = '0.1'
import pyhs2
class 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()
最新文章
- tomcat在linux中启动慢的解决方案
- Makefile中的特殊宏定义以及实用选项
- http状态码代表含义
- Duilib创建窗口双击标题栏禁止窗口最大化
- Linux 命令 - ps: 显示当前进程的快照
- JS函数的参数对象arguments在严格模式下的限制
- ANDROID_MARS学习笔记_S01原始版_007_Handler及线程的简单使用
- dapper的一个小扩展以支持dataset
- OSG中的几何体
- 有关nginx的配置文件 之server
- TCP/IP 协议 OSI七层协议
- 【BZOJ2142】礼物(拓展卢卡斯定理)
- node.js初识10
- 安全检测:2013 Top 10 List
- Nginx Configuration 免费HTTPS加密证书
- P3007 [USACO11JAN]大陆议会The Continental Cowngress
- ASP.NET Web API编程——使用自签名SSL证书
- 12-oauth密码模式identity server4实现
- Android 垃圾回收,用软引用建立缓存
- Fineui往框架添加选项卡的方法