首先python脚本连接presto 官方提供了presto-python-clienthttps://github.com/prestodb/presto-python-client,第三方也有提供pyhivehttps://github.com/dropbox/PyHive,我这里使用的是presto-python-client,毕竟是官方的。
安装presto-python-client,在linux机器中,使用pip3 install presto-python-client。 如果你用的python2之类的,就使用pip;如果没有sudo权限安装失败,后面接–user,eg:pip install presto-python-client --user。
接下来我们看presto设置的连接配置 配置默认是在presto安装目录的config.properties内。 如果你知道安装目录自然好说,不知道的话,用find / -name presto -type d从/文件夹开始查找名为presto的文件夹。没有sudo权限有文件夹会报permission deny无法查,但是一般都能搜到。 查到后的config.properties文件格式一般为:
coordinator=false node-scheduler.include-coordinator=false http-server.http.port=8088 #使用的端口 query.max-memory=500GB query.max-memory-per-node=10GB discovery.uri=XXX:8088 #使用的ip地址,这里看使用的是http还是https discovery-server.enabled=true #这个不开应该没法用脚本查 最后一步,就是写脚本啦~ 以下是参考:
import prestodb conn=prestodb.dbapi.connect( host=‘10.1234.5678’, # host位置 port=8088, # 端口位置 user=‘user’, # 用户名 catalog=‘hive’, # 使用的hive schema=‘default’, # 使用的schema,默认是default,可以不改 http_scheme=‘http’ #后面的暂时不添加,http的添加后报错, # auth=prestodb.auth.BasicAuthentication("", “”) ) conn._http_session.verify = ‘./presto.pem’ #校验文件存储位置,这个应该是默认位置 cur = conn.cursor() cur.execute(‘select * from schema.table’) # sql语句 rows = cur.fetchall() print(rows) 如果就是http的,可以参照上面的脚本来操作,我自己跑该脚本跑通了。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有