新聞中心
這里有您想知道的互聯網營銷解決方案
創(chuàng)新互聯Python教程:python連接hive的包是什么
python連接Hive的幾種方式

創(chuàng)新互聯堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網站制作、成都網站設計、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的貴港網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
·基于pyhive連接hive。
·基于impyla連接hive。
方法一:使用PyHive庫
安裝依賴包:其中sasl安裝可能會報錯,可以去https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl下載對應版本安裝。
pip install sasl pip install thrift pip install thrift-sasl pip install PyHive
相關推薦:《Python基礎教程》
Python腳本代碼操作:
from pyhive import hive # or import hive
conn = hive.Connection(host='****', port=****, username='****', database='****')
cursor.execute(''SELECT * FROM my_awesome_data LIMIT 10'')
for i in range(****):
sql = "INSERT INTO **** VALUES ({},'username{}')".format(value, str(username))
cursor.execute(sql)
# 下面是官網代碼:
from pyhive import presto # or import hive
cursor = presto.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print(cursor.fetchone())
print(cursor.fetchall())方法二:使用impyla庫
impyla依賴包:
pip install six pip install bit-array pip install thriftpy
為了支持Hive還需要以下兩個包:
pip install sasl pip install thrift-sasl
可在Python PyPI中下載impyla及其依賴包的源碼
Python腳本代碼:
from impala.dbapi import connect
conn = connect(host ='****',port = ****)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print cursor.description # 打印結果集的schema
results = cursor.fetchall() 當前名稱:創(chuàng)新互聯Python教程:python連接hive的包是什么
標題路徑:http://www.dlmjj.cn/article/coogses.html


咨詢
建站咨詢
