python调用hive与java调用区别_Python操作Hive的两种方法总结
方法一:使用PyHive庫(kù)pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
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)
# 下面是官網(wǎng)代碼:
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庫(kù)
impyla依賴包:pip install six
pip install bit_array
pip install thriftpy
為了支持Hive還需要以下兩個(gè)包: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 # 打印結(jié)果集的schema
results = cursor.fetchall()
與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的python调用hive与java调用区别_Python操作Hive的两种方法总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: python中for循环语句格式_关于P
- 下一篇: 基类的构造函数也可以被继承_「C++ P
