简介:

接到一个任务,需要从 hive 中读取数据,生成报表。

于是找到了官方文档:https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-PythonClientDriver

官方文档提供了一个使用 pyhs2 连接 hive 的例子,这本来很好的嘛。

结果去 Github:https://github.com/BradRuderman/pyhs2 瞅了一眼,很遗憾 pyhs2 项目已经不维护了。

不过,提供了两个很不错的替代项目:https://github.com/cloudera/impylahttps://github.com/dropbox/PyHive

终于绕到今天的主角了~

一、HiveServer2

  1. shell > cd /usr/local/apache-hive-2.3.-bin
  2.  
  3. shell > sh bin/hiveserver2 start > logs/beeline.log >& &
  4.  
  5. # 这就启动了,停止的话好像必须 kill pid。

二、impyla

  1. # 安装依赖
  2. shell > yum -y install gcc gcc-c++ cyrus-sasl-devel cyrus-sasl-plain
  3.  
  4. # 创建虚拟环境
  5. shell > virtualenv --no-site-packages -p python3 venv
  6.  
  7. # 启用虚拟环境
  8. shelll > source venv/bin/activate
  9.  
  10. (venv) shell > python -V
  11. Python 3.6.
  12.  
  13. # 安装 impyla 及所需依赖包
  14. (venv) shell > pip install ipython six bit_array thriftpy thrift_sasl==0.2. sasl impyla
  15.  
  16. (venv) shell > ipython
  17.  
  18. In []: from impala.dbapi import connect
  19.  
  20. In []: conn = connect(host="192.168.10.45", port=, database="logsdb", auth_mechanism="PLAIN")
  21.  
  22. In []: cur = conn.cursor()
  23.  
  24. In []: cur.execute("select count(*) from log_bftv_api")
  25.  
  26. In []: cur.fetchone()
  27. Out[]: (,)
  28.  
  29. In []: conn.close()
  30.  
  31. # 程序查出了 hive table log_bftv_api 中总共有 条数据。
  32.  
  33. # 其中,连接配置中 auth_mechanism 的值由 hive-site.xml 配置文件中 hive.server2.authentication 配置项指定。
  34.  
  35. # PLAIN 代表不启用认证,也就是 hive.server2.authentication 的默认值:NONE。

Python3 impyla 连接 hiveserver2的更多相关文章

  1. Python3实现连接SQLite数据库的方法

    本文实例讲述了Python3实现连接SQLite数据库的方法,对于Python的学习有不错的参考借鉴价值.分享给大家供大家参考之用.具体方法如下: 实例代码如下: ? 1 2 3 4 5 6 7 8 ...

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

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

  3. python3.5连接oracle数据及数据查询

    今天心血来潮研究下用python连接oracle数据库,看了一下demo,本以为很简单,从操作到成功还是有点坎坷,这里分享给大家,希望为后面学习的童鞋铺路. 一.首先按照cx_Oracle 二:在py ...

  4. 用Java代码通过JDBC连接Hiveserver2

    1.在终端启动hiveserver2#hiveserver2 2.使用beeline连接hive另外打开一个终端,输入如下命令(xavierdb必须是已经存在的数据库)#beeline -u jdbc ...

  5. 【原创】大叔经验分享(38)beeline连接hiveserver2报错impersonate

    beeline连接hiveserver2报错 Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost: ...

  6. python3.4连接mysql5.7数据库增删改查

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...

  7. 通过JDBC连接HiveServer2

    如果通过JDBC连接HiveServer2时提示:User: hive is not allowed to impersonate hive,需要在core-site.xml中新增如下配置: hado ...

  8. python3.4连接mysql数据库的方法

    python3.4连接mysql数据库的方法 发布时间:2014-08-04编辑:www.jbxue.com 本文介绍了python3.4连接mysql数据库的方法,在python3.4中不能用mys ...

  9. python3.6 连接mysql数据库问题

    最近有个项目欲安装MySQL-python/1.2.5一直失败. 环境: win7 python3.6.2 报错信息如下: Creating library build\temp.win32-3.6\ ...

随机推荐

  1. dslr control vis usb

    nikon https://sdk.nikonimaging.com/apply/compmail.do Digital-SLR cameras           We are offering L ...

  2. vuex、redux、mobx 对比

    出处:https://www.w3cplus.com/javascript/talk-about-front-end-state-management.html 其实大部分概念都差不多,只不过VUEX ...

  3. mysql 事务隔离级别详解

    事物的 隔离级别,说简单非常简单(新手也能说出 是个隔离级别 和 影响),说男也非常难.(很多 有几年编程 经验的程序员依旧搞不清楚) 废话不多少 直接开始: 事务的隔离级别 是用来描述 事务的读关系 ...

  4. php 5.2.17 升级到5.3.29

    修改php.ini配置文件 register_globals =On include_path = ".;d:/testoa/webroot" error_reporting = ...

  5. IE 10 如何设置支持CRM4 正常浏览

    通过工具—> 选择兼容性视图 就可以了.具体如下图:

  6. VS2005的depends工具 (分析EXE)

    忙乎了近两个月,程序开始打包供外部调用了,连同其所需的dll文件,这就需要使用VC自带的Depends软件,在VS2005中其路径为:D:\Program Files\Microsoft Visual ...

  7. 如何在UltraEdit中高亮显示PB代码

    打开UE,从菜单中选择高级->配置… 点击打开按钮,注意文件WordFile.txt最后一个高亮显示语言的编号,格式为“ /L(number) ”,假设最后一个高亮显示语言的编号是15,修改UE ...

  8. busybox下的tftp client

    # tftp -p -l file host    # put local file to remote host # tftp -g -r file host    # get remote fil ...

  9. HA 高可用mysql集群

    注意问题: 1.保持mysql用户和组的ID号是一致的: 2.filesystem 共享存储必须要有写入权限: 3.删除资源必须先删除约束,在删除资源: 1.安装数据库,这里使用maridb数据库: ...

  10. Spring Cloud config之一:分布式配置中心入门介绍

    Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务器为各应用的所有环境提供了一个中心化的外部配置.它实现了对服务端和客户端对Spring Environm ...