use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class TestClientOptions method testSource.
@Test
public void testSource() {
ClientOptions options = new ClientOptions();
options.source = "test";
ClientSession session = options.toClientSession();
assertEquals(session.getSource(), "test");
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class TestClientOptions method testServerHostOnly.
@Test
public void testServerHostOnly() {
ClientOptions options = new ClientOptions();
options.server = "localhost";
ClientSession session = options.toClientSession();
assertEquals(session.getServer().toString(), "http://localhost:80");
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class AbstractTestingPrestoClient method execute.
public T execute(Session session, @Language("SQL") String sql) {
ResultsSession<T> resultsSession = getResultSession(session);
ClientSession clientSession = toClientSession(session, prestoServer.getBaseUrl(), true, new Duration(2, TimeUnit.MINUTES));
try (StatementClient client = new StatementClient(httpClient, QUERY_RESULTS_CODEC, clientSession, sql)) {
while (client.isValid()) {
QueryResults results = client.current();
resultsSession.addResults(results);
client.advance();
}
if (!client.isFailed()) {
QueryResults results = client.finalResults();
if (results.getUpdateType() != null) {
resultsSession.setUpdateType(results.getUpdateType());
}
if (results.getUpdateCount() != null) {
resultsSession.setUpdateCount(results.getUpdateCount());
}
return resultsSession.build(client.getSetSessionProperties(), client.getResetSessionProperties());
}
QueryError error = client.finalResults().getError();
verify(error != null, "no error");
if (error.getFailureInfo() != null) {
throw error.getFailureInfo().toException();
}
throw new RuntimeException("Query failed: " + error.getMessage());
// dump query info to console for debugging (NOTE: not pretty printed)
// JsonCodec<QueryInfo> queryInfoJsonCodec = createCodecFactory().prettyPrint().jsonCodec(QueryInfo.class);
// log.info("\n" + queryInfoJsonCodec.toJson(queryInfo));
}
}
use of com.facebook.presto.client.ClientSession in project presto by prestodb.
the class BenchmarkDriver method run.
public void run(Suite suite) throws Exception {
// select queries to run
List<BenchmarkQuery> queries = suite.selectQueries(this.queries);
if (queries.isEmpty()) {
return;
}
Map<String, String> properties = new HashMap<>();
properties.putAll(clientSession.getProperties());
properties.putAll(suite.getSessionProperties());
ClientSession session = ClientSession.withProperties(clientSession, properties);
// select schemas to use
List<BenchmarkSchema> benchmarkSchemas;
if (!suite.getSchemaNameTemplates().isEmpty()) {
List<String> schemas = queryRunner.getSchemas(session);
benchmarkSchemas = suite.selectSchemas(schemas);
} else {
benchmarkSchemas = ImmutableList.of(new BenchmarkSchema(session.getSchema()));
}
if (benchmarkSchemas.isEmpty()) {
return;
}
for (BenchmarkSchema benchmarkSchema : benchmarkSchemas) {
for (BenchmarkQuery benchmarkQuery : queries) {
session = ClientSession.withCatalogAndSchema(session, session.getCatalog(), benchmarkSchema.getName());
BenchmarkQueryResult result = queryRunner.execute(suite, session, benchmarkQuery);
resultsStore.store(benchmarkSchema, result);
}
}
}
Aggregations