Search in sources :

Example 6 with PrestoConnection

use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.

the class JdbcPrestoAction method getConnection.

private PrestoConnection getConnection(QueryStage queryStage, String clientInfo) throws SQLException {
    PrestoConnection connection = DriverManager.getConnection(jdbcUrlSelector.next(), queryConfiguration.getUsername().orElse(null), queryConfiguration.getPassword().orElse(null)).unwrap(PrestoConnection.class);
    try {
        connection.setClientInfo("ApplicationName", applicationName);
        connection.setClientInfo("ClientInfo", clientInfo);
        connection.setCatalog(queryConfiguration.getCatalog());
        connection.setSchema(queryConfiguration.getSchema());
    } catch (SQLClientInfoException ignored) {
    // Do nothing
    }
    Map<String, String> sessionProperties = mangleSessionProperties(queryConfiguration.getSessionProperties(), queryStage, getTimeout(queryStage), removeMemoryRelatedSessionProperties);
    for (Entry<String, String> entry : sessionProperties.entrySet()) {
        connection.setSessionProperty(entry.getKey(), entry.getValue());
    }
    return connection;
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) PrestoConnection(com.facebook.presto.jdbc.PrestoConnection)

Example 7 with PrestoConnection

use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.

the class JdbcDriverUtils method setSessionProperty.

public static void setSessionProperty(Connection connection, String key, String value) throws SQLException {
    if (usingPrestoJdbcDriver(connection)) {
        PrestoConnection prestoConnection = connection.unwrap(PrestoConnection.class);
        prestoConnection.setSessionProperty(key, value);
    } else if (usingTeradataJdbcDriver(connection)) {
        try (Statement statement = connection.createStatement()) {
            if (shouldValueBeQuoted(value)) {
                value = "'" + value + "'";
            }
            statement.execute(String.format("set session %s=%s", key, value));
        }
    } else {
        throw new IllegalStateException();
    }
}
Also used : Statement(java.sql.Statement) PrestoConnection(com.facebook.presto.jdbc.PrestoConnection)

Aggregations

PrestoConnection (com.facebook.presto.jdbc.PrestoConnection)7 PrestoStatement (com.facebook.presto.jdbc.PrestoStatement)2 ProductTest (io.prestodb.tempto.ProductTest)2 SQLClientInfoException (java.sql.SQLClientInfoException)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Test (org.testng.annotations.Test)2 QueryResult (com.facebook.presto.benchmark.framework.QueryResult)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 QueryResult (io.prestodb.tempto.query.QueryResult)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Map (java.util.Map)1