Ready to get started?

Learn more about the CData JDBC Driver for Presto or download a free trial:

Download Now

Work with Presto Data in Apache Spark Using SQL

Access and process Presto Data in Apache Spark using the CData JDBC Driver.

Apache Spark is a fast and general engine for large-scale data processing. When paired with the CData JDBC Driver for Presto, Spark can work with live Presto data. This article describes how to connect to and query Presto data from a Spark shell.

The CData JDBC Driver offers unmatched performance for interacting with live Presto data due to optimized data processing built into the driver. When you issue complex SQL queries to Presto, the driver pushes supported SQL operations, like filters and aggregations, directly to Presto and utilizes the embedded SQL engine to process unsupported operations (often SQL functions and JOIN operations) client-side. With built-in dynamic metadata querying, you can work with and analyze Presto data using native data types.

Install the CData JDBC Driver for Presto

Download the CData JDBC Driver for Presto installer, unzip the package, and run the JAR file to install the driver.

Start a Spark Shell and Connect to Presto Data

  1. Open a terminal and start the Spark shell with the CData JDBC Driver for Presto JAR file as the jars parameter: $ spark-shell --jars /CData/CData JDBC Driver for Presto/lib/cdata.jdbc.presto.jar
  2. With the shell running, you can connect to Presto with a JDBC URL and use the SQL Context load() function to read a table.

    Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.

    To enable TLS/SSL, set UseSSL to true.

    Authenticating with LDAP

    In order to authenticate with LDAP, set the following connection properties:

    • AuthScheme: Set this to LDAP.
    • User: The username being authenticated with in LDAP.
    • Password: The password associated with the User you are authenticating against LDAP with.

    Authenticating with Kerberos

    In order to authenticate with KERBEROS, set the following connection properties:

    • AuthScheme: Set this to KERBEROS.
    • KerberosKDC: The Kerberos Key Distribution Center (KDC) service used to authenticate the user.
    • KerberosRealm: The Kerberos Realm used to authenticate the user with.
    • KerberosSPN: The Service Principal Name for the Kerberos Domain Controller.
    • KerberosKeytabFile: The Keytab file containing your pairs of Kerberos principals and encrypted keys.
    • User: The user who is authenticating to Kerberos.
    • Password: The password used to authenticate to Kerberos.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the Presto JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

    java -jar cdata.jdbc.presto.jar

    Fill in the connection properties and copy the connection string to the clipboard.

    Configure the connection to Presto, using the connection string generated above.

    scala> val presto_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:presto:Server=127.0.0.1;Port=8080;").option("dbtable","Customer").option("driver","cdata.jdbc.presto.PrestoDriver").load()
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the Presto data as a temporary table:

    scala> presto_df.registerTable("customer")
  5. Perform custom SQL queries against the Data using commands like the one below:

    scala> presto_df.sqlContext.sql("SELECT FirstName, LastName FROM Customer WHERE Id = 123456789").collect.foreach(println)

    You will see the results displayed in the console, similar to the following:

Using the CData JDBC Driver for Presto in Apache Spark, you are able to perform fast and complex analytics on Presto data, combining the power and utility of Spark with your data. Download a free, 30 day trial of any of the 190+ CData JDBC Drivers and get started today.