1 使用pyhive
官网: https://github.com/dropbox/PyHive
pip install pyhive
import pandas as pd
from sqlalchemy.engine import create_engine
from pyhive import hive
engine = create_engine('presto://$ip:$port/$catalog')
# 准备语句
sql = "select * from $schema.$table"
# 获取数据
df = pd.read_sql(sql, engine)
print(df)
2 使用presto-python-client
官网:https://github.com/prestodb/presto-python-client
pip install presto-python-client
import prestodb
conn=prestodb.dbapi.connect(
host='$ip',
port=$port,
catalog=$catalog
)
cur = conn.cursor()
cur.execute('SELECT * FROM $schema.$table')
rows = cur.fetchall()
print(rows )