Use the command-line interface (CLI) to connect to Trino and run SQL queries after you create an E-MapReduce (EMR) cluster with the Trino service.
Prerequisites
Before you begin, ensure that you have:
-
An EMR cluster with the Trino service. For more information, see Create a cluster
Limitations
Ranger authentication and Kerberos authentication cannot be enabled on the same cluster at the same time.
DataLake clusters and custom clusters
When you create a cluster, turning on Kerberos Authentication makes it a high-security cluster. Otherwise, it is a common cluster.
The CLI binary name depends on your EMR version. In EMR V3.44.0 and later, or EMR V5.10.0 and later, the service is named Trino and the binary istrino. In earlier versions, the service is named Presto and the binary ispresto.
Common clusters
-
Log on to your cluster in SSH mode. For more information, see Log on to a cluster.
-
Connect to the Trino CLI.
In EMR V3.44.0, EMR V5.10.0, or a minor version later than EMR V3.44.0 or EMR V5.10.0
trino --server master-1-1:9090In a minor version earlier than EMR V3.44.0 or EMR V5.10.0
presto --server master-1-1:9090 -
Query a table:
Placeholder Description Example <catalog>The name of the data source hive<schema>The name of the database default<table>The name of the table to query testselect * from <catalog>.<schema>.<table>;Replace the placeholders with actual values: For example, to query the
testtable in the default Hive database:select * from hive.default.test; -
(Optional) Run
quit;to exit the CLI.
High-security clusters
High-security clusters use Kerberos authentication over HTTPS. The connection command requires both TLS (keystore) and Kerberos (keytab) parameters.
Tip: Save the connection command as a shell script to avoid retyping it every session.
-
Log on to your cluster in SSH mode. For more information, see Log on to a cluster.
-
Connect to the Trino CLI.
In EMR V3.44.0, EMR V5.10.0, or a minor version later than EMR V3.44.0 or EMR V5.10.0
trino --server https://${FQDN}:7778 \ --krb5-config-path /etc/krb5.conf \ --keystore-path /etc/emr/trino-conf/keystore \ --keystore-password ${pwd} \ --krb5-keytab-path /etc/emr/trino-conf/trino.keytab \ --krb5-principal trino/${FQDN}@${REALM} \ --krb5-remote-service-name trino \ --user trino/${FQDN} \ --catalog ${CATALOG}In a minor version earlier than EMR V3.44.0 or EMR V5.10.0
presto --server https://${FQDN}:7778 \ --krb5-config-path /etc/krb5.conf \ --keystore-path /etc/emr/trino-conf/keystore \ --keystore-password ${pwd} \ --krb5-keytab-path /etc/emr/trino-conf/trino.keytab \ --krb5-principal trino/${FQDN}@${REALM} \ --krb5-remote-service-name trino \ --user trino/${FQDN}Parameter Description How to obtain ${FQDN}Fully Qualified Domain Name (FQDN) of the master-1-1 node. Format: master-1-1.c-xxxxxxx.cn-xxxxxx.emr.aliyuncs.comRun hostname -fon the master-1-1 node${pwd}Value of http-server.https.keystore.keyin config.propertiesRun awk -F= '/http-server.https.keystore.key/{print $2}' ${TRINO_CONF_DIR}/config.propertieson the master-1-1 node${REALM}Kerberos realm. Format: EMR.C-XXXXXX.COMCheck http-server.authentication.krb5.user-mapping.patternin config.properties${CATALOG}The data source to connect to For example, hiveParameter Fixed value --krb5-config-path/etc/krb5.conf--keystore-path/etc/emr/trino-conf/keystore--krb5-keytab-path/etc/emr/trino-conf/trino.keytab--krb5-remote-service-nametrinoReplace the placeholders with values from your cluster: The following parameters have fixed values in EMR:
-
List the schemas in the connected catalog:
show schemas; -
(Optional) Run
quit;to exit the CLI.
Hadoop clusters
What's next
Use Java Database Connectivity (JDBC) to connect to Trino for querying, analyzing, and processing complex data, or to integrate query results into Java applications. For more information, see Use JDBC.