prestopresto-jdbc

Adding client tags to presto jdbc connection


I am using jdbc to connect to presto server.

From the documentation, I am able to connect to the server and run queries. https://prestodb.io/docs/current/installation/jdbc.html

I am facing issues while sending ClientTags (X-Presto-Client-Tags) in the connection/statement.

Here's the function to build a connection and run a query.

public void test() {
    java.util.Properties info = new java.util.Properties();

    if (PRESTO_USER != null) {
        info.put("user", PRESTO_USER);
    }
    if (PRESTO_PASSWORD != null) {
        info.put("password", PRESTO_PASSWORD);
    }
        info.put("ClientTags", "my,tag");



    try (Connection connection = DriverManager.getConnection(PRESTO_URL, info);
         Statement statement = connection.createStatement()) {
        testBody(connection, statement);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Exception occured");
    }
}

However, it fails with

java.sql.SQLException: Unrecognized connection property 'ClientTags'
    at com.facebook.presto.jdbc.PrestoDriverUri.validateConnectionProperties(PrestoDriverUri.java:316)

For pyhive, I was able to override the session and pass client tags https://github.com/dropbox/PyHive/issues/283. Can this be done for jdbc driver too?


Solution

  • It's currently not possible to set ClientTags on the connection URL. Please create a feature request @ https://github.com/trinodb/trino/issues/

    Currently, the only way is to use Connection method:

    Connection connection = DriverManager.getConnection("....");
    connection.unwrap(PrestoConnection.class)
      .setClientInfo("ClientTags", "one,two,three");