Search in sources :

Example 6 with QueryResults

use of io.prestosql.client.QueryResults in project hetu-core by openlookeng.

the class TestServer method testQuery.

@Test
public void testQuery() {
    // start query
    Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_PATH, "path").setHeader(PRESTO_CLIENT_INFO, "{\"clientVersion\":\"testVersion\"}").addHeader(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").addHeader(PRESTO_SESSION, JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").addHeader(PRESTO_PREPARED_STATEMENT, "foo=select * from bar").build();
    QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
    ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
    while (queryResults.getNextUri() != null) {
        queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
        if (queryResults.getData() != null) {
            data.addAll(queryResults.getData());
        }
    }
    assertNull(queryResults.getError());
    // get the query info
    BasicQueryInfo queryInfo = server.getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
    // verify session properties
    assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").build());
    // verify client info in session
    assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    // verify prepared statements
    assertEquals(queryInfo.getSession().getPreparedStatements(), ImmutableMap.builder().put("foo", "select * from bar").build());
    // only the system catalog exists by default
    List<List<Object>> rows = data.build();
    assertEquals(rows, ImmutableList.of(ImmutableList.of("system")));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.prestosql.spi.QueryId) Request(io.airlift.http.client.Request) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) QueryResults(io.prestosql.client.QueryResults) Test(org.testng.annotations.Test)

Example 7 with QueryResults

use of io.prestosql.client.QueryResults in project hetu-core by openlookeng.

the class TestServer method testInvalidSessionError.

@Test
public void testInvalidSessionError() {
    String invalidTimeZone = "this_is_an_invalid_time_zone";
    Request request = preparePost().setHeader(PRESTO_USER, "user").setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_PATH, "path").setHeader(PRESTO_TIME_ZONE, invalidTimeZone).build();
    QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
    while (queryResults.getNextUri() != null) {
        queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
    }
    QueryError queryError = queryResults.getError();
    assertNotNull(queryError);
    TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
    assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
    assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
    assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
    assertEquals(queryError.getMessage(), expected.getMessage());
}
Also used : Request(io.airlift.http.client.Request) QueryError(io.prestosql.client.QueryError) TimeZoneNotSupportedException(io.prestosql.spi.type.TimeZoneNotSupportedException) QueryResults(io.prestosql.client.QueryResults) Test(org.testng.annotations.Test)

Example 8 with QueryResults

use of io.prestosql.client.QueryResults in project hetu-core by openlookeng.

the class TestServer method testTransactionSupport.

@Test
public void testTransactionSupport() {
    Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_TRANSACTION_ID, "none").build();
    JsonResponse<QueryResults> queryResults = client.execute(request, createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
    ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
    while (true) {
        if (queryResults.getValue().getData() != null) {
            data.addAll(queryResults.getValue().getData());
        }
        if (queryResults.getValue().getNextUri() == null) {
            break;
        }
        queryResults = client.execute(prepareGet().setUri(queryResults.getValue().getNextUri()).build(), createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
    }
    assertNull(queryResults.getValue().getError());
    assertNotNull(queryResults.getHeader(PRESTO_STARTED_TRANSACTION_ID));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Request(io.airlift.http.client.Request) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) QueryResults(io.prestosql.client.QueryResults) Test(org.testng.annotations.Test)

Example 9 with QueryResults

use of io.prestosql.client.QueryResults in project hetu-core by openlookeng.

the class TestServer method testNoTransactionSupport.

@Test
public void testNoTransactionSupport() {
    Request request = preparePost().setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8)).setHeader(PRESTO_USER, "user").setHeader(PRESTO_SOURCE, "source").build();
    QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
    while (queryResults.getNextUri() != null) {
        queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
    }
    assertNotNull(queryResults.getError());
    assertEquals(queryResults.getError().getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode().getCode());
}
Also used : Request(io.airlift.http.client.Request) QueryResults(io.prestosql.client.QueryResults) Test(org.testng.annotations.Test)

Example 10 with QueryResults

use of io.prestosql.client.QueryResults in project hetu-core by openlookeng.

the class TestQueryResource method runToCompletion.

private String runToCompletion(String sql) {
    URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
    Request request = preparePost().setHeader(PRESTO_USER, "user").setUri(uri).setBodyGenerator(createStaticBodyGenerator(sql, UTF_8)).build();
    QueryResults queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    while (queryResults.getNextUri() != null) {
        request = prepareGet().setHeader(PRESTO_USER, "user").setUri(queryResults.getNextUri()).build();
        queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    }
    return queryResults.getId();
}
Also used : Request(io.airlift.http.client.Request) URI(java.net.URI) QueryResults(io.prestosql.client.QueryResults)

Aggregations

QueryResults (io.prestosql.client.QueryResults)10 Request (io.airlift.http.client.Request)6 List (java.util.List)4 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)3 URI (java.net.URI)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 HttpClient (io.airlift.http.client.HttpClient)1 HttpUriBuilder.uriBuilderFrom (io.airlift.http.client.HttpUriBuilder.uriBuilderFrom)1 JsonResponseHandler.createJsonResponseHandler (io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler)1 Builder.prepareGet (io.airlift.http.client.Request.Builder.prepareGet)1 Builder.preparePost (io.airlift.http.client.Request.Builder.preparePost)1 StaticBodyGenerator.createStaticBodyGenerator (io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator)1 UnexpectedResponseException (io.airlift.http.client.UnexpectedResponseException)1 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)1 AsyncResponseHandler.bindAsyncResponse (io.airlift.jaxrs.AsyncResponseHandler.bindAsyncResponse)1 JsonCodec (io.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (io.airlift.json.JsonCodec.jsonCodec)1 JsonCodec.listJsonCodec (io.airlift.json.JsonCodec.listJsonCodec)1 Closeables.closeQuietly (io.airlift.testing.Closeables.closeQuietly)1