Search in sources :

Example 11 with ClientSession

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");
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Example 12 with ClientSession

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");
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Example 13 with ClientSession

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));
    }
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) StatementClient(com.facebook.presto.client.StatementClient) Duration(io.airlift.units.Duration) QueryError(com.facebook.presto.client.QueryError) QueryResults(com.facebook.presto.client.QueryResults)

Example 14 with ClientSession

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ClientSession(com.facebook.presto.client.ClientSession)

Aggregations

ClientSession (com.facebook.presto.client.ClientSession)14 Test (org.testng.annotations.Test)8 Duration (io.airlift.units.Duration)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 QueryError (com.facebook.presto.client.QueryError)1 QueryResults (com.facebook.presto.client.QueryResults)1 StatementClient (com.facebook.presto.client.StatementClient)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteStreams.nullOutputStream (com.google.common.io.ByteStreams.nullOutputStream)1 Command (io.airlift.airline.Command)1 HelpOption (io.airlift.airline.HelpOption)1 SingleCommand.singleCommand (io.airlift.airline.SingleCommand.singleCommand)1 KerberosConfig (io.airlift.http.client.spnego.KerberosConfig)1 Level (io.airlift.log.Level)1 Logging (io.airlift.log.Logging)1 LoggingConfiguration (io.airlift.log.LoggingConfiguration)1