Python使用presto

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 )
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章