使用python3连接hiveserver2的方法
生活随笔
收集整理的這篇文章主要介紹了
使用python3连接hiveserver2的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 前言:
- 1、啟動HiveServer2
- 2、在Linux中安裝impyla(前提是安裝Python相關的環境、虛擬環境(可選))
前言:
需求:需要通過windows端的pycharm來操作hive。
于是就搜集資料尋找解決方案。
大概有三種方式:
協商后決定還是用imply。
以下是整個安裝以及驗證的過程:
1、啟動HiveServer2
shell > cd /usr/local/apache-hive-2.3.1-binshell > nohup hiveserver2 1>/root/apps/hive-2.1.1/logs/hiveserver.log 2>/root/apps/hive-2.1.1/logs/hiveserver.err &(后臺啟動并將hivesever的日志導入對應的目錄)2、在Linux中安裝impyla(前提是安裝Python相關的環境、虛擬環境(可選))
# 安裝依賴 shell > yum -y install gcc gcc-c++ cyrus-sasl-devel cyrus-sasl-plain# 創建虛擬環境(linux下安裝虛擬環境參考:) shell > virtualenv --no-site-packages -p python3 venv# 啟用虛擬環境 shelll > source venv/bin/activate#linux下python的安裝教程見: (venv) shell > python -V Python 3.6.3# 安裝 impyla 及所需依賴包 (venv) shell > pip install ipython six bit_array thriftpy thrift_sasl==0.2.1 sasl impyla(venv) shell > ipythonIn [1]: from impala.dbapi import connectIn [2]: conn = connect(host="192.168.10.45", port=10000, database="logsdb", auth_mechanism="PLAIN")In [3]: cur = conn.cursor()In [4]: cur.execute("select count(*) from log_bftv_api")In [5]: cur.fetchone() Out[5]: (1379094425,)In [6]: conn.close()# 程序查出了 hive table log_bftv_api 中總共有 1379094425 條數據。你也可以到對應yarn的web界面去查看對應執行進度,或者在1中配置的日志文件中查看執行的過程。# 其中,連接配置中 auth_mechanism 的值由 hive-site.xml 配置文件中 hive.server2.authentication 配置項指定,你需要到對應的hiveserver2節點的hive-site中添加如下配置: <property><name>hive.server2.authentication</name><value>PLAIN</value> </property>。# PLAIN 代表不啟用認證,也就是 hive.server2.authentication 的默認值:NONE。轉自:https://www.cnblogs.com/wangxiaoqiangs/p/7850953.html
總結
以上是生活随笔為你收集整理的使用python3连接hiveserver2的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将文件提交到github的两种方法
- 下一篇: python乱码大赛_FishC工作室《