use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class PrestoConnection method startQuery.
StatementClient startQuery(String sql) {
String source = firstNonNull(clientInfo.get("ApplicationName"), "presto-jdbc");
ClientSession session = new ClientSession(httpUri, user, source, clientInfo.get("ClientInfo"), catalog.get(), schema.get(), timeZoneId.get(), locale.get(), ImmutableMap.copyOf(sessionProperties), transactionId.get(), false, new Duration(2, MINUTES));
return queryExecutor.startQuery(session, sql);
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class Console method process.
private static void process(QueryRunner queryRunner, String sql, OutputFormat outputFormat, boolean interactive) {
try (Query query = queryRunner.startQuery(sql)) {
query.renderOutput(System.out, outputFormat, interactive);
ClientSession session = queryRunner.getSession();
// update session properties if present
if (!query.getSetSessionProperties().isEmpty() || !query.getResetSessionProperties().isEmpty()) {
Map<String, String> sessionProperties = new HashMap<>(session.getProperties());
sessionProperties.putAll(query.getSetSessionProperties());
sessionProperties.keySet().removeAll(query.getResetSessionProperties());
session = withProperties(session, sessionProperties);
}
// update prepared statements if present
if (!query.getAddedPreparedStatements().isEmpty() || !query.getDeallocatedPreparedStatements().isEmpty()) {
Map<String, String> preparedStatements = new HashMap<>(session.getPreparedStatements());
preparedStatements.putAll(query.getAddedPreparedStatements());
preparedStatements.keySet().removeAll(query.getDeallocatedPreparedStatements());
session = withPreparedStatements(session, preparedStatements);
}
// update transaction ID if necessary
if (query.isClearTransactionId()) {
session = stripTransactionId(session);
}
if (query.getStartedTransactionId() != null) {
session = withTransactionId(session, query.getStartedTransactionId());
}
queryRunner.setSession(session);
} catch (RuntimeException e) {
System.err.println("Error running command: " + e.getMessage());
if (queryRunner.getSession().isDebug()) {
e.printStackTrace();
}
}
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class TestClientOptions method testUpdateSessionParameters.
@Test
public void testUpdateSessionParameters() throws Exception {
ClientOptions options = new ClientOptions();
ClientSession session = options.toClientSession();
SqlParser sqlParser = new SqlParser();
ImmutableMap<String, String> existingProperties = ImmutableMap.of("query_max_memory", "10GB", "distributed_join", "true");
ImmutableMap<String, String> preparedStatements = ImmutableMap.of("my_query", "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_catalog.test_schema"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog");
assertEquals(session.getSchema(), "test_schema");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_schema_b"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog");
assertEquals(session.getSchema(), "test_schema_b");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_catalog_2.test_schema"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog_2");
assertEquals(session.getSchema(), "test_schema");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class TestTableNameCompleter method testAutoCompleteWithoutSchema.
@Test
public void testAutoCompleteWithoutSchema() {
ClientSession session = new ClientOptions().toClientSession();
QueryRunner runner = QueryRunner.create(session, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), false, null);
TableNameCompleter completer = new TableNameCompleter(runner);
assertEquals(completer.complete("SELECT is_infi", 14, ImmutableList.of()), 7);
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class TestClientOptions method testDefault.
@Test
public void testDefault() {
ClientSession session = new ClientOptions().toClientSession();
assertEquals(session.getServer().toString(), "http://localhost:8080");
assertEquals(session.getSource(), "presto-cli");
}
Aggregations