Connecting to Trino
Trino offers an SQL endpoint via a HTTP API. An open source JDBC driver does exist as well as a proprietary ODBC driver.
Multiple SQL clients can be used to connect to Trino as described below.
Prerequisites
The Trino server must be reachable from your local computer. It is typically secured via HTTPS with a certificated provided by a SecretClass.
As most setups use a self-signed certificate, that cannot be verified without the CA certificate, the easiest way is to disable the Trino cert validation as the following guide will do, however this is not secure!
To use certificate validation instead, you need to extract the ca.crt
file from the the SecretClass and provide it to the Trino client.
Connect with trino-cli
Consult the official trino-cli docs for details on how to connect to a running Trino cluster.
The --insecure
flag is required in this case, so your command looks something like:
$ java -jar ~/Downloads/trino-cli-403-executable.jar --server https://85.215.195.29:8443 --user admin --password --insecure
Connect with DBeaver
DBeaver is a free multi-platform database tool for anyone who needs to work with databases. It is installed locally and can connect to Trino and offers a convenient UI to explore and work with Trino.
First of you need to click on the New Database Connection icon, select Other > Trino.
Afterwards you need to enter the Host and Port as well as Username and Password.
After entering the details you need to switch to the tab called Driver properties.
First action is to click on the SSL
driver property and enter the value true
.
Additionally you need to click on the green plus icon in the bottom left corner to add a User Property called SSLVerification
.
Afterwards you need to set the value to NONE
.
As the last step you can click on Finish and start using the Trino connection.
Connect with Python
For more information on how to connect to Trino from Python, have a look at the official trino-python-client.
A minimal example of making a connection and running a query looks like this:
def get_connection():
connection = trino.dbapi.connect(
host="trino-coordinator-default.default.svc.cluster.local",
http_scheme="https",
verify=False, # For best security you can also provide a path to the trino root ca: "/stackable/secrets/trino-ca-cert/ca.crt",
port=8443,
user="admin",
auth=trino.auth.BasicAuthentication("admin", "adminadmin"),
catalog="hive",
schema="staging",
)
return connection
def run_query(connection, query):
# print(f"[DEBUG] Executing query {query}")
cursor = connection.cursor()
cursor.execute(query)
return cursor.fetchall()
connection = get_connection()
run_query(connection, "show catalogs")