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

  

windows下32位没成功,报错(64位可以http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载

  File "build\bdist.win32\egg\pyhs2\cloudera\thrift_sasl.py", line , in open
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in
sasl_client_start (-) SASL(-): no mechanism available: Unable to find a callba
python -m pip install -U pip
python -m pip install pyOpenSSL https://pypi.python.org/pypi/pyhs2 python -m pip install sasl http://aka.ms/vcpython27 python -m pip install sasl-0.2.-cp27-cp27m-win32.whl
python -m pip install thrift-0.10.-cp27-cp27m-win32.whl

linux安装

pyhs2,cyrus-sasl(cyrus-sasl-plain  cyrus-sasl-devel  cyrus-sasl-gssapi),gcc,libxml2-devel,libxslt-devel

python访问hive的更多相关文章

  1. 其它语言通过HiveServer2访问Hive

    先解释一下几个名词: metadata :hive元数据,即hive定义的表名,字段名,类型,分区,用户这些数据.一般存储关系型书库mysql中,在测试阶段也可以用hive内置Derby数据库. me ...

  2. pyinstaller打包python源程序访问hive

    1.需求 使用hvie server一段时间后,业务部门需要自己不定时的查询业务数据,之前这一块都是他们提需求我们来做,后来发现这样重复一样的工作放在我们这边做是在没有效率,遂提出给他们工具或者web ...

  3. Spark&Hive:如何使用scala开发spark访问hive作业,如何使用yarn resourcemanager。

    背景: 接到任务,需要在一个一天数据量在460亿条记录的hive表中,筛选出某些host为特定的值时才解析该条记录的http_content中的经纬度: 解析规则譬如: 需要解析host: api.m ...

  4. 调用javaAPI访问hive

    jdbc远程连接hiveserver2 2016-04-26 15:59 本站整理 浏览(425)     在之前的学习和实践Hive中,使用的都是CLI或者hive –e的方式,该方式仅允许使用Hi ...

  5. SparkSQL On Yarn with Hive,操作和访问Hive表

    转载自:http://lxw1234.com/archives/2015/08/466.htm 本文将介绍以yarn-cluster模式运行SparkSQL应用程序,访问和操作Hive中的表,这个和在 ...

  6. Python访问sqlite3数据库取得dictionary的正路!

    [引子] 很多人都知道,Python里是内置了很好用的sqlite3的.但这个库有个缺陷,在执行fetchall()/fetchone()等方法后,得到的是一个tuple.以前吧,做自己的小项目,tu ...

  7. python 访问 zookeeper

    python 访问 zookeeper zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同 ...

  8. python访问redis

    python访问redis 1 Linux上安装redis a) 下载 $ wget http://download.redis.io/releases/redis-3.0.5.tar.gz b) 编 ...

  9. ActiveMQ:使用Python访问ActiveMQ

    Windows 10家庭中文版,Python 3.6.4,stomp.py 4.1.21 ActiveMQ支持Python访问,提供了基于STOMP协议(端口为61613)的库. ActiveMQ的官 ...

随机推荐

  1. node api 之:util

    util 库的使用: const util = require('util'); util 的方法: 方法 含义 util.inherits(constructor, superConstructor ...

  2. 代码风格统一工具:EditorConfig 和 静态代码检查工具:ESLint

    EditorConfig 最常见的用途是:统一文件的编码字符集以及缩进风格 使用 Eslint 做代码 lint,那么为什么还要使用 .editorconfig 呢?细细想了下,应该有两个方面吧. E ...

  3. SpringBoot+Maven 多模块项目的构建、运行、打包

    SpringBoot+Maven 多模块项目的构建.运行.打包 https://blog.csdn.net/zekeTao/article/details/79413919

  4. golang语言并发与并行——goroutine和channel的详细理解(一) 转发自https://blog.csdn.net/skh2015java/article/details/60330785

    如果不是我对真正并行的线程的追求,就不会认识到Go有多么的迷人. Go语言从语言层面上就支持了并发,这与其他语言大不一样,不像以前我们要用Thread库 来新建线程,还要用线程安全的队列库来共享数据. ...

  5. jQuery实现商品详情 详细参数页面切换

    利用index实现: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  6. Python实例讲解 -- wxpython 基本的控件 (按钮)

    使用按钮工作 在wxPython 中有很多不同类型的按钮.这一节,我们将讨论文本按钮.位图按钮.开关按钮(toggle buttons )和通用(generic )按钮. 如何生成一个按钮? 在第一部 ...

  7. java流程控制与选择控制

    流程控制语句 顺序   程序的正常执行 选择 if else多重if,嵌套if,switch; 循环 for whlie,do whlie; 案例1 自己对代码进行改进!!!!!!!!!!!!!!! ...

  8. chrome flash

    chrome://settings/content/flash 在Chrome地址栏中输入:chrome://settings/content/flash,进入Flash设置,勾选允许网站运行flas ...

  9. InfluxDB HTTP API reference

    InfluxDB HTTP API reference API地址:https://docs.influxdata.com/influxdb/v1.6/tools/api/ The InfluxDB ...

  10. 黄聪:PHP JSON_ENCODE 不转义中文汉字的方法

    ios程序中不识别读取到的JSON数据中 \u开头的数据. PHP 生成JSON的时候,必须将汉字不转义为 \u开头的UNICODE数据. 网上很多,但是其实都是错误的,正确的方法是在json_enc ...