Presto JDBC Connection

This page describes how to connect to Treasure Data’s Presto using our JDBC Driver.

Table of Contents

Setup

  • Download presto-jdbc driver
    • For using secure HTTPS (port 443) connection you need to use presto 0.148 or later.
  • Use the following parameters to connect prestobase on development server:
    • Driver name: com.facebook.presto.jdbc.PrestoDriver
    • user: (Your TD API key)
    • password: (dummy string. This value will be ignored)
      • Since presto-jdbc 0.180, because of this bug some dummy string needs to be set to the password.

Connection URL examples:

Connection URL needs to have the following format: jdbc:presto://api-presto.treasuredata.com:443/td-presto/(database name)?SSL=true

Examples:

jdbc:presto://api-presto.treasuredata.com:443/td-presto?SSL=true
jdbc:presto://api-presto.treasuredata.com:443/td-presto/sample_datasets?SSL=true

Example Code

$ javac Sample.java
$ java -cp .:presto-jdbc-0.152.jar Sample (your TD API key)
time=1412351990, method=GET, path=/category/office
time=1412351976, method=GET, path=/item/software/2265
time=1412351961, method=GET, path=/category/toys
time=1412351947, method=GET, path=/item/electronics/3305
time=1412351932, method=GET, path=/category/software

Sample.java

import java.sql.*;

class Sample {
  public static void main(String[] args) {
    if(args.length != 1) {
      System.err.println("Please pass your TD API key as an argument");
      return;
    }

    String apikey = args[0];
    try {
      Connection conn = DriverManager.getConnection("jdbc:presto://api-presto.treasuredata.com:443/td-presto/sample_datasets?SSL=true", apikey, "dummy_password");
      Statement stmt = conn.createStatement();
      try {
        ResultSet rs = stmt.executeQuery("SELECT time, method, path from www_access limit 5");
        while(rs.next()) {
            long time = rs.getLong(1);
            String method = rs.getString(2);
            String path = rs.getString(3);
            System.out.println(String.format("time=%s, method=%s, path=%s", time, method, path));
        }
      }
      finally {
        stmt.close();
        conn.close();
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Notice

Connection via presto-jdbc has several limitations:

  • PreparedStatements is not yet supported
  • setAutoCommit(false) will throw an exception since we are not supporting transactions.
  • presto-jdbc queries share the same presto resources you have available for any other ad-hoc or scheduled queries you submit from the Treasure Data console or via REST API.
  • presto-jdbc queries will be shown in your account’s job log, although the following information, normally available, will not be shown on the job page:
    • Query result table
    • Query plan (will be included soon)
    • Progress log (will be included soon)
  • The query result is converted into JSON before being submitted back to separate tools for display. As such, very large result tables may take some time before being displayed. We don’t expect this to be a major issue, but if you are having latency problems, please let us know and we’ll investigate.
  • Certain BI tools issue “information_schema” requests that cause failed queries in our system. We will be addressing this shortly, but may be an issue in your tool upon first use.
  • If you see any unexpected errors/bugs/logs that occur during beta use, please let us know and we will address as quickly as possible.
  • Our aim is to keep this API up as much as possible. Specifically, we expect to achieve a downtime of less than 1 hour total per month.

Last modified: Nov 30 2017 17:33:03 UTC

If this article is incorrect or outdated, or omits critical information, let us know. For all other issues, access our support channels.