This topic describes how to use a Python client to access Trino on ACK and perform query operations.
Background information
For more information about Trino Java DataBase Connectivity (JDBC) and related parameters, see trino-python-client.
Prerequisites
A Presto cluster is created on the EMR on ACK page of the new E-MapReduce (EMR) console. For more information, see Getting started.
The AliyunOSSFullAccess and AliyunDLFFullAccess policies are attached to your account. For more information, see Grant permissions to a role.
Python, pip, Trino Python Database API (DBAPI), or SQLAlchemy is installed in the development environment. For more information, see Environment requirements.
Use Trino DBAPI to access Trino on ACK
URL: You can obtain the URL that is used to access the Trino web UI on the Access Links and Ports tab. Then, changetrinoin the URL totrino-cli.Username and password: The default username
adminand the password that you configured for the user are used.
Sample DBAPI.python file:
from trino.dbapi import connect
from trino.auth import BasicAuthentication
conn = connect(
port=443,
# The URL.
host="trino-cli.c-xxx.xxx.cn-hangzhou.alicontainer.com",
# The username and password.
auth=BasicAuthentication("xxx", "xxx"),
http_scheme="https",
verify=False
)
cur = conn.cursor()
cur.execute("show catalogs")
rows = cur.fetchall()Use SQLAlchemy to access Trino on ACK
URL: You can obtain the URL that is used to access the Trino web UI on the Access Links and Ports tab. Then, changetrinoin the URL totrino-cli.Username and password: The default username
adminand the password that you configured for the user are used.
Sample SQLAlchemy.python file:
from sqlalchemy import create_engine
from sqlalchemy.sql.expression import text
from trino.auth import BasicAuthentication
engine = create_engine(
# The URL.
"trino://trino-cli.c-xxx.xxx.cn-hangzhou.alicontainer.com:443",
connect_args={
# The username and password.
"auth": BasicAuthentication("xxx", "xxx"),
"http_scheme": "https",
"verify": False,
}
)
connection = engine.connect()
rows = connection.execute(text("show catalogs")).fetchall()