Use the Presto command-line interface (CLI) to connect to a Presto cluster and run SQL queries against your data.
Prerequisites
Before you begin, make sure you have:
-
An E-MapReduce (EMR) cluster of V3.45.0, V5.11.0, or a later minor version with the Presto service deployed. For more information, see Create a cluster.
Common clusters
A common cluster is one created without Kerberos Authentication enabled.
-
Log on to the cluster over SSH. For more information, see Log on to a cluster.
-
Open the Presto CLI:
presto --server master-1-1:8889A successful connection displays the
presto>prompt. Runhelpto see all supported commands, orquit;to exit. -
Explore available data sources before running queries. If you don't know which catalogs and schemas are available, run the following commands:
-- List all catalogs (data sources) show catalogs; -- List schemas in a catalog show schemas from <catalog>; -- Set a default catalog and schema to avoid typing the full path each time use <catalog>.<schema>;You can also view all catalogs on the Configure tab of the Presto service page in the EMR console.
-
Query table data:
Parameter Description <catalog>The data source to connect to <schema>The database to query <table>The table to query select * from <catalog>.<schema>.<table>;For example, to query the
testtable in the default Hive database:select * from hive.default.test; -
(Optional) Exit the Presto CLI:
quit;
High-security clusters
A high-security cluster is one created with Kerberos Authentication enabled.
High-security clusters are accessible only over HTTPS. The HTTP port 8889 is disabled — http-server.http.port is overwritten by http-server.https.port. Use HTTPS port 7779 instead.
-
Log on to the cluster over SSH. For more information, see Log on to a cluster.
-
Open the Presto CLI with Kerberos authentication:
presto --server https://${FQDN}:7779 \ --krb5-config-path /etc/krb5.conf \ --keystore-path /etc/emr/presto-conf/keystore \ --keystore-password ${pwd} \ --krb5-keytab-path /etc/emr/presto-conf/presto.keytab \ --krb5-principal presto/${FQDN}@${REALM} \ --krb5-remote-service-name presto \ --user presto/${FQDN}The following table describes the parameters you need to supply:
Parameter Description ${FQDN}The fully qualified domain name (FQDN) of the master-1-1 node, in the format master-1-1.c-xxxxxxx.cn-xxxxxx.emr.aliyuncs.com. Runhostname -fto get the value.--krb5-config-pathThe path to the Kerberos configuration file. Fixed value: /etc/krb5.conf. Corresponds tohttp.authentication.krb5.configin config.properties.--keystore-pathThe path to the TLS keystore. Fixed value: /etc/emr/presto-conf/keystore. Corresponds tohttp-server.https.keystore.pathin config.properties.--keystore-passwordThe keystore password. Corresponds to http-server.https.keystore.keyin config.properties. Run the following command on the master-1-1 node to get the value:awk -F= '/http-server.https.keystore.key/{print $2}' ${PRESTO_CONF_DIR}/config.properties--krb5-keytab-pathThe path to the Kerberos keytab file. Fixed value: /etc/emr/presto-conf/presto.keytab. Corresponds tohttp.server.authentication.krb5.keytabin config.properties.${REALM}The Kerberos realm. Unlike the Kerberos realm for Trino, the Kerberos realm for Presto is not stored in the Presto configuration file. Check /etc/krb5.conffor the value — in EMR, the format isEMR.C-XXXXXX.COM.--krb5-remote-service-nameFixed value: presto. Corresponds tohttp.server.authentication.krb5.service-namein config.properties. -
Query table data:
select * from <catalog>.<schema>.<table>;For parameter descriptions and examples, see step 4 in Common clusters.
-
(Optional) Exit the Presto CLI:
quit;
What's next
Use Java Database Connectivity (JDBC) to connect to Presto for querying, analyzing, and processing complex data, or to integrate query results into Java applications. For more information, see Use JDBC.