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 )