本文主要是介绍impyla的安装方式及Python连接hive/impala/pg的方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python impyla的安装方式
pip install six bit_array thrift==0.9.3 thrift_sasl==0.2.1 pure_sasl impyla==0.14.0
Python连接hive/impala/pg数据库的方式
python连接hive,impala
# hive 默认端口为10000,impala端口为21050from impala.dbapi import connectcdh_params = {'host': '10.xxx.xx.xx','port':10000,'database': 'xx','timeout': 60,'auth_mechanism':'PLAIN', # hive PLAIN'user': 'xx','password': 'xx'
}cdh_params = {'host': '10.xxx.xx.xx','port':21050,'database': 'xx','timeout': 60,'auth_mechanism':'NOSASL', # impala NOSASL'user': 'xx','password': 'xx'
}cdh_conn = connect(**cdh_params)
cdh_cursor = cdh_conn.cursor()cdh_cursor.execute('SHOW Tables')
cdh_tabs = cdh_cursor.fetchall()
python连接pg(PostgreSQL )
import psycopg2cdh_params = {'host': '10.xx.xx.xx','port':5432,'database': 'xx','user': 'xx','password': 'xx'
}cdh_conn=psycopg2.connect(**cdh_params)
cdh_cursor = cdh_conn.cursor()# 获取xx模式下的所有表
cdh_cursor.execute("select tablename from pg_tables where schemaname = 'xxx'")
cdh_tabs = cdh_cursor.fetchall()
python 通过Presto连接hive
import jaydebeapi# 参数1:驱动类
# 参数2:jdbc
# 参数3:user password
# 参数4:jar包本地路径bdp_conn = jaydebeapi.connect('com.facebook.presto.jdbc.PrestoDriver','jdbc:presto://10.xx.xx.xx:4380/hive/dc_src?&SSL=true&SSLKeyStorePath=/Applications/DBeaver.app/Contents/MacOS/keystore.jks&SSLKeyStorePassword=xxxx',{'user': "xxx", 'password': "xxx",},"/Users/shylin/.dbeaver-drivers/maven/maven-central/com.facebook.presto/presto-jdbc-0.216.jar")
bdp_cursor = bdp_conn.cursor()bdp_cursor.execute('SHOW Tables')
Shylin
这篇关于impyla的安装方式及Python连接hive/impala/pg的方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!