LBForum

LBForum
A Forum powered by Django
Home » Test

大师傅大师傅

By tuteng at Sept. 28, 2018, 9:59 a.m., 96 hits

两种方式:impyla,pyhive
注意:目前的版本,impyla依赖thrift0.9.3,pyhive依赖thrift0.10+,因此两者不兼容

一、impyla
安装
yum install -y gcc-c++ python-devel cyrus-sasl-devel cyrus-sasl-plain
pip install thrift-sasl
pip install impyla
示例
from impala import dbapi
cursor_hive = dbapi.connect(host='172.20.12.7', port=10000, auth_mechanism='PLAIN', user='xxxx', password='xxxx').cursor()
cursor_impala = dbapi.connect(host='172.20.12.8', port=21050, auth_mechanism='PLAIN', user='xxxx', password='xxxx').cursor()
cursor_hive.execute('SELECT 1 + 1')
cursor_impala.execute('SELECT 1 + 1')
print(cursor_hive.fetchall())
print(cursor_impala.fetchall())

二、pyhive
安装
yum install -y gcc-c++ python-devel cyrus-sasl-devel cyrus-sasl-plain
pip install sasl
pip install thrift
pip install thrift-sasl
pip install pyhive
示例
from pyhive import hive
cursor = hive.connect('172.20.12.7').cursor()
cursor.execute('SELECT 1 + 1')
print(cursor.fetchall())

 
No Reply
Quick reply to this topic
You may use: BBCode
Copyright © 2010 ~ 2016 vicalloy
Powered by LBForum