JDBC ドライバを使用して Treasure Data の Trino (別名 PrestoSQL) に接続します。
Trino JDBC 接続にはいくつかの制限があります:
setAutoCommit(false) はトランザクションがサポートされていないため例外をスローします。
presto-jdbc クエリは、TD Console または REST API から送信する他のアドホックまたはスケジュールされたクエリに利用可能な同じ Presto リソースを共有します。
presto-jdbc クエリは、以下の標準エントリを除いて、アカウントのジョブログに表示されます:
クエリ結果テーブル
クエリプラン
進行状況ログ
クエリ結果は、別々のツールで表示するために送り返される前に JSON に変換されます。そのため、非常に大きな結果テーブルは表示されるまでに時間がかかる場合があります。レイテンシの問題がある場合は、サポートにお問い合わせください。
特定の BI ツールは、システムで失敗したクエリを引き起こす「information_schema」リクエストを発行します。これは、最初の使用時にツールで問題になる可能性があります。
ベータ使用中に発生した予期しないエラー/バグ/ログが表示された場合は、サポートにお問い合わせください。
この API を可能な限り稼働し続けることを目指しています。具体的には、月に合計1時間未満のダウンタイムを達成することを期待しています。
- ダウンロード
セキュアな HTTPS (ポート 443) 接続を使用するには、presto 0.148 以降を使用する必要があります。
開発サーバーで prestobase に接続するには、以下のパラメータを使用します:
ドライバ名:
io.trino.jdbc.TrinoDriver (PrestoSQL Driver を使用する場合は、io.prestosql.jdbc.PrestoDriver を使用できます)user: (TD API キー)
password: (ダミー文字列。この値は無視されます)
- presto-jdbc 0.180 以降、バグのため、パスワードにダミー文字列を設定する必要があります。
接続 URL は以下の形式である必要があります:
jdbc:trino://api-presto.treasuredata.com:443/td-presto/(database name)?SSL=true
または
jdbc:presto://api-presto.treasuredata.com:443/td-presto/(database name)?SSL=true
例:
jdbc:trino://api-presto.treasuredata.com:443/td-presto/sample_datasets?SSL=true
または
jdbc:presto://api-presto.treasuredata.com:443/td-presto/sample_datasets?SSL=true
$ javac Sample.java
$ java -cp .:trino-jdbc-0.359.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/softwareimport java.sql.*;
class Sample {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Provide your TD API key as an argument");
return;
}
String apikey = args[0];
try {
Connection conn = DriverManager.getConnection("jdbc:trino://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();
}
}
}