我正在尝试替换Jaydebeapi with the Presto-Python-Client by Facebook问题是如何替换身份验证位
db = jaydebeapi.connect(connection['jclass'], connection['host'],[ connection['user'], connection['pass']], connection['jar'])
而使用 presto-python-client
import prestodb
conn= prestodb.dbapi.connect(
host='localhost',
port=8080,
user='the-user',
catalog='the-catalog',
schema='the-schema',
isolation_level=transaction.IsolationLevel.REPEATABLE_READ,
)
而且我找不到任何地方来指定如何传递密码。此更改的原因是我在尝试使用 jaydebeapi 传递长查询(18k 个字符)时出现歧义错误
我们最终使用了SQLAlchemy,所以解决方案是
from sqlalchemy.engine import create_engine
engine = create_engine('presto://{0}:{1}@{2}:{3}/hive'.format(connection['user'],connection['pass'],connection['host'],int(connection['port'])), connect_args={'protocol': 'https', 'requests_kwargs': {'verify': False}})
db = engine.raw_connection()
现在旧方法已被弃用,所以这里是连接到presto的新方法
cursor = presto.connect(presto_host,
presto_port,
requests_kwargs={'auth': HTTPBasicAuth(presto_username, presto_password)},
poll_interval=1,
protocol='https',
source='pyhive').cursor()