sudo pip install pyhs2

网上找的例子:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# hive util with hive server2
"""
@author:knktc
@create:2014-04-08 16:55
"""
__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='221.143.68.22', port=10000, user='hdfs', password='mypass', database='default', authMechanism='PLAIN') result = hive_client.query('select * from test limit 10') print result hive_client.close() if __name__ == '__main__': main()

官网例子:


import pyhs2 with pyhs2.connect(host='localhost', port=10000, authMechanism="PLAIN", user='root', password='test', database='default') as conn: with conn.cursor() as cur: #Show databases print cur.getDatabases() #Execute query cur.execute("select * from table") #Return column info from query print cur.getSchema() #Fetch table results for i in cur.fetch(): print i

https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-PythonClientDriver

python连接hiveserver2的更多相关文章

  1. 【初学python】使用python连接mysql数据查询结果并显示

    因为测试工作经常需要与后台数据库进行数据比较和统计,所以采用python编写连接数据库脚本方便测试,提高工作效率,脚本如下(python连接mysql需要引入第三方库MySQLdb,百度下载安装) # ...

  2. python连接mysql的驱动

    对于py2.7的朋友,直接可以用MySQLdb去连接,但是MySQLdb不支持python3.x.这是需要注意的~ 那应该用什么python连接mysql的驱动呢,在stackoverflow上有人解 ...

  3. paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误

    paip. 解决php 以及 python 连接access无效的参数量.参数不足,期待是 1"的错误 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源 ...

  4. python 连接sql server

    linux 下pymssql模块的安装 所需压缩包:pymssql-2.1.0.tar.bz2freetds-patched.tar.gz 安装: tar -xvf pymssql-2.1.0.tar ...

  5. paip.python连接mysql最佳实践o4

    paip.python连接mysql最佳实践o4 python连接mysql 还使用了不少时间...,相比php困难多了..麻烦的.. 而php,就容易的多兰.. python标准库没mysql库,只 ...

  6. python连接字符串的方式

    发现Python连接字符串又是用的不顺手,影响速度 1.数字对字符进行拼接 s=""  #定义这个字符串,方便做连接 print type(s) for i in range(10 ...

  7. python连接zookeeper的日志问题

    用python连接zookeeper时,在终端里,一直会有zookeeper的日志冒出来,这样会很烦. -- ::,:(: Exceeded deadline by 11ms 解决方法是在连接后设置一 ...

  8. 由“Beeline连接HiveServer2后如何使用指定的队列(Yarn)运行Hive SQL语句”引发的一系列思考

    背景   我们使用的HiveServer2的版本为0.13.1-cdh5.3.2,目前的任务使用Hive SQL构建,分为两种类型:手动任务(临时分析需求).调度任务(常规分析需求),两者均通过我们的 ...

  9. python 连接Mysql数据库

    1.下载http://dev.mysql.com/downloads/connector/python/ 由于Python安装的是3.4,所以需要下载下面的mysql-connector-python ...

随机推荐

  1. The connection to adb is down, and a severe error has occured.

    启动android模拟器时.有时会报The connection to adb is down, and a severe error has occured.的错误.在网友说在任务管理器上把所有ad ...

  2. 【shell】 for循环

    #!/bin/bash for i in 1,3,4,6 ##有几个数就循环几次 do echo $i done for m in $( cat /root/num.log) ## /root/num ...

  3. js 标签云效果

    下载:http://files.cnblogs.com/zjfree/js_tag_list.rar 效果如下: 源码如下: <html> <head> <meta ht ...

  4. 像学历史课本一样学习Perl

    第一次接触Perl,还是2008年10月份的时候,当时因为项目重构,需要进行大量的文本操作,于是便拾起了以“文本操作为己任”的Perl语言.当然,带我入门的还是那本赫赫有名的The Llama  Bo ...

  5. select,epool,pool解释

    内容主要来自搜狗实验室技术交流文档, 编写链接数巨大的高负载服务器程序时,经典的多线程模式和select模式都不再适合了.应该采用epool/kqueue/dev_pool来捕获IO事件. ----- ...

  6. 只有一个Service或Broadcast Reciver的android应用

    Service是android四大组件中与Activity最相似的组件,都可以代表可执行的程序. Service与Activity的区别在于:   (1).Service一直在后台运行,没有用户界面. ...

  7. 黄聪:C#设置窗体打开位置(在显示器的右下角打开)

    ; ; this.SetDesktopLocation(x, y); 注释:System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Wid ...

  8. [jQuery]attr和prop的区别

    转自:http://www.cnblogs.com/Showshare/p/different-between-attr-and-prop.html 在高版本的jquery引入prop方法后,什么时候 ...

  9. [JS]setInterval,setTimeout的使用以及伪随机数

  10. hdu 5774 Where Amazing Happens

    Where Amazing Happens 题意: 让你输出各个队名的出现次数. 题解: 打表题,好坑,相同的没有放在一起,需要认真找,否则容易错. 代码: #include<iostream& ...