All Products
Search
Document Center

E-MapReduce:Use the CLI to connect to Presto

Last Updated:Jan 17, 2024

This topic describes how to use the CLI to connect to Presto and use Presto to query data.

Prerequisites

An E-MapReduce (EMR) cluster of V3.45.0, V5.11.0, or a minor version later than V3.45.0 or V5.11.0 with the Presto service deployed is created. For more information, see Create a cluster.

Common clusters

Note

If you do not turn on Kerberos Authentication when you create a cluster, the cluster is a common cluster.

  1. Log on to the desired cluster in SSH mode. For more information, see Log on to a cluster.

  2. Run the following command to open the Presto CLI:

    presto --server master-1-1:8889
  3. Execute the following statement to view the table data:

    select * from <catalog>.<schema>.<table>;

    Parameters in the preceding statement:

    • <catalog>: specifies the name of the data source that you want to connect to.

      You can run the show catalogs; command to view all catalogs. You can also view all catalogs on the Configure tab of the Presto service page in the EMR console.

    • <schema>: specifies the name of the database from which you want to query data.

    • <table>: specifies the name of the table from which you want to query data.

      For example, if you want to query data from the test table in the default database of Hive, you can execute the select * from hive.default.test; statement.

  4. Optional. Run the quit; command to exit the Presto CLI.

High-security clusters

Note

If you turn on Kerberos Authentication when you create a cluster, the cluster is a high-security cluster.

  1. Log on to the desired cluster in SSH mode. For more information, see Log on to a cluster.

  2. Run the following command to open the Presto CLI:

    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}
    Important

    You can access the Presto service of a high-security cluster only over HTTPS. The HTTP port 8889 is inaccessible, and the specified http-server.http.port is overwritten by http-server.https.port. You can use only the HTTPS port 7779 to access the Presto service.

    Parameter

    Description

    ${FQDN}

    The fully qualified domain name (FQDN) of the master-1-1 node. The FQDN must be in the master-1-1.c-xxxxxxx.cn-xxxxxx.emr.aliyuncs.com format. You can run the hostname -f command to obtain the FQDN.

    --krb5-config-path

    The value of the http.authentication.krb5.config parameter in the config.properties file. The value is fixed as /etc/krb5.conf.

    --keystore-path

    The value of the http-server.https.keystore.path parameter in the config.properties file. The value is fixed as /etc/emr/presto-conf/keystore.

    --keystore-password

    The value of the http-server.https.keystore.key parameter in the config.properties file. In this example, the value is ${pwd}. You need to obtain the value on your own. You can run the awk -F= '/http-server.https.keystore.key/{print $2}' ${PRESTO_CONF_DIR}/config.properties command on the master-1-1 node to obtain the value.

    --krb5-keytab-path

    The value of the http-server.authentication.krb5.keytab parameter in the config.properties file. The value is fixed as /etc/emr/presto-conf/presto.keytab.

    ${REALM}

    The Kerberos realm. You need to obtain the value on your own. Unlike the Kerberos realm for Trino, the Kerberos realm for Presto is not configured in the configuration file. You can view the Kerberos realm in the krb5.conf file that is stored in the /etc directory. In EMR, the Kerberos realm is in the EMR.C-XXXXXX.COM format.

    --krb5-remote-service-name

    The value of the http.server.authentication.krb5.service-name parameter in the config.properties file. The value is fixed as presto.

  3. Execute the following statement to view the table data:

    select * from <catalog>.<schema>.<table>;

    Parameters in the preceding statement:

    • <catalog>: specifies the name of the data source that you want to connect to.

      You can run the show catalogs; command to view all catalogs. You can also view all catalogs on the Configure tab of the Presto service page in the EMR console.

    • <schema>: specifies the name of the database from which you want to query data.

    • <table>: specifies the name of the table from which you want to query data.

      For example, if you want to query data from the test table in the default database of Hive, you can execute the select * from hive.default.test; statement.

  4. Optional. Run the quit; command to exit the Presto CLI.

References

You can use Java Database Connectivity (JDBC) to connect to Presto to query, analyze, and process complex data, or integrate query results into Java applications. For more information, see Use JDBC.