python-pyhs2
#!/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()
python-pyhs2的更多相关文章
- python连接hiveserver2
sudo pip install pyhs2 网上找的例子: #!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive s ...
- python升级导致的坑
问题来源 问题往往都是这样来的突然,让我措手不及. 小孩没娘说来话长啊,操作系统是centos6.5因此默认自带的python是2.6.6的,突然有一天我要写一个关于kafka topic消费情况的监 ...
- python脚本 用sqoop把mysql数据导入hive
转:https://blog.csdn.net/wulantian/article/details/53064123 用python把mysql数据库的数据导入到hive中,该过程主要是通过pytho ...
- python访问hive
#!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive server2 """ @auth ...
- python -- Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
用python读取hive数据,引用下面包. #!/usr/bin/env python import pyhs2 as hive 先按照它 pip install pyhs2 出现错误 Collec ...
- A Python example for HiveServer2
要做一个通过调用python来实现对hive server2 的连接.在网上搜索了很多资料,有些说的hive sever的,但是由于认证方式发生改变,行不通. 最后,找到了权威的说明(PS: 还是应该 ...
- python socketpool:通用连接池(转)
简介 在软件开发中经常要管理各种“连接”资源,通常我们会使用对应的连接池来管理,比如mysql数据库连接可以用sqlalchemy中的池来管理,thrift连接可以通过thriftpool管理,red ...
- python socketpool:通用连接池
简介 在软件开发中经常要管理各种“连接”资源,通常我们会使用对应的连接池来管理,比如mysql数据库连接可以用sqlalchemy中的池来管理,thrift连接可以通过thriftpool管理,red ...
- Python常用模块安装
1. python操作MySQL数据库的依赖包MySQLdb ImportError: No module named MySQLdb 安装方式: yum install MySQL-python 2 ...
- python hive
sudo apt-get install sasl2-bin sudo apt-get install libsasl2-dev pip install pyhs2 pip install pyhiv ...
随机推荐
- id和class的区别
id和class是定义css样式用到的,不同的是定义样式时的写法不一样,使用id选择样式时,定义的格式为 #main{width:20px;} ,使用class时用到的是 .main{width:20 ...
- winfrom 点击按钮button弹框显示颜色集
1.窗体托一个按钮button: 2.单击事件: private void btnForeColor_Click(object sender, EventArgs e) { using (ColorD ...
- sql当前时间往后半年
select DATEADD(MONTH, -6, GETDATE()) select DATEADD(hh, -6, GETDATE())
- java实现spark常用算子之mapPartitionsWithIndex
import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...
- nginx之配置
1)反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端, ...
- form表单中的enctype 属性以及post请求里Content-Type方式
对于form表单中的enctype 属性之前理解的一般,就知道是类似于一种编码形式.后来公司做一个form表单提交数据的时候,重点是这个form表单里有文件上传,而我又要用vue来模拟form表单提交 ...
- 绑定css样式,点击高亮
<div class="flex-lay" style="color:#999"> <div bindtap="changeType ...
- java字符常量
在Java程序中经常会遇到类似于"Hello"这样地字符串,那么这种类型的字符串是Java中是如何存储,下面就说明字符串常量在内存中存储方式: Java程序在编译时会将程序中出现的 ...
- 单节点FastDFS与Nginx部署
一.安装基本组件 1.安装编译需要的组件,必安装组件. yum install gcc-c++ 2.安装libevent函数库.pcre-devel zlib-devel必安装组件. yum ...
- 下拉菜单 Spinner 简单纯字符串版
下拉菜单 Spinner 简单纯字符串版 public class MainActivity extends Activity implements AdapterView.OnItemSelecte ...