use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcTests method shouldSetLocale.
@Test(groups = JDBC)
public void shouldSetLocale() throws SQLException {
if (usingPrestoJdbcDriver(connection())) {
((PrestoConnection) connection()).setLocale(CHINESE);
try (Statement statement = connection().createStatement()) {
QueryResult result = queryResult(statement, "SELECT date_format(TIMESTAMP '2001-01-09 09:04', '%M')");
assertThat(result).contains(row("一月"));
}
} else {
LOGGER.warn("shouldSetLocale() only applies to PrestoJdbcDriver");
}
}
use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcPrestoAction method executeOnce.
private <T> T executeOnce(Statement statement, QueryStage queryStage, StatementExecutor<T> statementExecutor) {
String query = formatSql(statement, Optional.empty());
String clientInfo = new ClientInfo(testId, testName, verificationContext.getSourceQueryName(), verificationContext.getSuite()).serialize();
try (PrestoConnection connection = getConnection(queryStage, clientInfo)) {
try (java.sql.Statement jdbcStatement = connection.createStatement()) {
PrestoStatement prestoStatement = jdbcStatement.unwrap(PrestoStatement.class);
prestoStatement.setProgressMonitor(statementExecutor.getProgressMonitor());
return statementExecutor.execute(prestoStatement, query);
}
} catch (SQLException e) {
throw exceptionClassifier.createException(queryStage, statementExecutor.getProgressMonitor().getLastQueryStats(), e);
}
}
use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcPrestoAction method getConnection.
private PrestoConnection getConnection() throws SQLException {
PrestoConnection connection = DriverManager.getConnection(jdbcUrl, "user", null).unwrap(PrestoConnection.class);
try {
connection.setClientInfo("ApplicationName", "benchmark-test");
connection.setCatalog(benchmarkQuery.getCatalog());
connection.setSchema(benchmarkQuery.getSchema());
} catch (SQLClientInfoException ignored) {
// Do nothing
}
Map<String, String> sessionProperties = ImmutableMap.<String, String>builder().putAll(benchmarkQuery.getSessionProperties()).put(QUERY_MAX_EXECUTION_TIME, queryTimeout.toString()).build();
for (Map.Entry<String, String> entry : sessionProperties.entrySet()) {
connection.setSessionProperty(entry.getKey(), entry.getValue());
}
return connection;
}
use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcPrestoAction method executeOnce.
private <R> QueryResult<R> executeOnce(Statement statement, Optional<ResultSetConverter<R>> converter) {
String query = formatSql(statement, Optional.empty());
ProgressMonitor progressMonitor = new ProgressMonitor();
try (PrestoConnection connection = getConnection()) {
try (java.sql.Statement jdbcStatement = connection.createStatement()) {
PrestoStatement prestoStatement = jdbcStatement.unwrap(PrestoStatement.class);
prestoStatement.setProgressMonitor(progressMonitor);
ImmutableList.Builder<R> rows = ImmutableList.builder();
if (converter.isPresent()) {
try (ResultSet resultSet = jdbcStatement.executeQuery(query)) {
while (resultSet.next()) {
rows.add(converter.get().apply(resultSet));
}
}
} else {
boolean moreResults = jdbcStatement.execute(query);
if (moreResults) {
consumeResultSet(jdbcStatement.getResultSet());
}
do {
moreResults = jdbcStatement.getMoreResults();
if (moreResults) {
consumeResultSet(jdbcStatement.getResultSet());
}
} while (moreResults || jdbcStatement.getUpdateCount() != -1);
}
checkState(progressMonitor.getLastQueryStats().isPresent(), "lastQueryStats is missing");
return new QueryResult<>(rows.build(), progressMonitor.getLastQueryStats().get());
}
} catch (SQLException e) {
throw exceptionClassifier.createException(progressMonitor.getLastQueryStats(), e);
}
}
use of com.facebook.presto.jdbc.PrestoConnection in project presto by prestodb.
the class JdbcTests method shouldSetTimezone.
@Test(groups = JDBC)
public void shouldSetTimezone() throws SQLException {
String timeZoneId = "Indian/Kerguelen";
if (usingPrestoJdbcDriver(connection())) {
((PrestoConnection) connection()).setTimeZoneId(timeZoneId);
assertConnectionTimezone(connection(), timeZoneId);
} else {
String prestoJdbcURLTestTimeZone;
String testTimeZone = "TimeZoneID=" + timeZoneId + ";";
if (prestoJdbcURL.contains("TimeZoneID=")) {
prestoJdbcURLTestTimeZone = prestoJdbcURL.replaceFirst("TimeZoneID=[\\w/]*;", testTimeZone);
} else {
prestoJdbcURLTestTimeZone = prestoJdbcURL + ";" + testTimeZone;
}
Connection testConnection = DriverManager.getConnection(prestoJdbcURLTestTimeZone, prestoJdbcUser, prestoJdbcPassword);
assertConnectionTimezone(testConnection, timeZoneId);
}
}
Aggregations