#!/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()

最新文章

  1. tomcat在linux中启动慢的解决方案
  2. Makefile中的特殊宏定义以及实用选项
  3. http状态码代表含义
  4. Duilib创建窗口双击标题栏禁止窗口最大化
  5. Linux 命令 - ps: 显示当前进程的快照
  6. JS函数的参数对象arguments在严格模式下的限制
  7. ANDROID_MARS学习笔记_S01原始版_007_Handler及线程的简单使用
  8. dapper的一个小扩展以支持dataset
  9. OSG中的几何体
  10. 有关nginx的配置文件 之server
  11. TCP/IP 协议 OSI七层协议
  12. 【BZOJ2142】礼物(拓展卢卡斯定理)
  13. node.js初识10
  14. 安全检测:2013 Top 10 List
  15. Nginx Configuration 免费HTTPS加密证书
  16. P3007 [USACO11JAN]大陆议会The Continental Cowngress
  17. ASP.NET Web API编程——使用自签名SSL证书
  18. 12-oauth密码模式identity server4实现
  19. Android 垃圾回收,用软引用建立缓存
  20. Fineui往框架添加选项卡的方法

热门文章

  1. 【原创】大叔经验分享(61)kudu rebalance报错
  2. JS基础_for循环练习2
  3. Oracle连接字符串总结(转)
  4. 使用spring的test时,当配置文件不在classpath下,而在WEB-INF下
  5. .NET中跨线程访问winform控件的方法
  6. 创建LEANGOO项目
  7. Python实现串口通信(pyserial)
  8. Linux下的用户和用户组,文件权限:chown和chmod
  9. ProgressDialog 进度条的初步认识
  10. 从n个数里面找最大的两个数理论最少需要比较