Search in sources :

Example 1 with TestingTrinoClient

use of io.trino.testing.TestingTrinoClient in project trino by trinodb.

the class RedisQueryRunner method createRedisQueryRunner.

public static DistributedQueryRunner createRedisQueryRunner(RedisServer redisServer, Map<String, String> extraProperties, String dataFormat, Iterable<TpchTable<?>> tables) throws Exception {
    DistributedQueryRunner queryRunner = null;
    try {
        queryRunner = DistributedQueryRunner.builder(createSession()).setExtraProperties(extraProperties).build();
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        Map<SchemaTableName, RedisTableDescription> tableDescriptions = createTpchTableDescriptions(queryRunner.getCoordinator().getTypeManager(), tables, dataFormat);
        installRedisPlugin(redisServer, queryRunner, tableDescriptions);
        TestingTrinoClient trinoClient = queryRunner.getClient();
        log.info("Loading data...");
        long startTime = System.nanoTime();
        for (TpchTable<?> table : tables) {
            loadTpchTable(redisServer, trinoClient, table, dataFormat);
        }
        log.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS));
        redisServer.destroyJedisPool();
        return queryRunner;
    } catch (Throwable e) {
        closeAllSuppress(e, queryRunner, redisServer);
        throw e;
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) TestingTrinoClient(io.trino.testing.TestingTrinoClient) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 2 with TestingTrinoClient

use of io.trino.testing.TestingTrinoClient in project trino by trinodb.

the class ElasticsearchQueryRunner method createElasticsearchQueryRunner.

public static DistributedQueryRunner createElasticsearchQueryRunner(HostAndPort address, Iterable<TpchTable<?>> tables, Map<String, String> extraProperties, Map<String, String> extraConnectorProperties, int nodeCount) throws Exception {
    RestHighLevelClient client = null;
    DistributedQueryRunner queryRunner = null;
    try {
        queryRunner = DistributedQueryRunner.builder(createSession()).setExtraProperties(extraProperties).setNodeCount(nodeCount).build();
        queryRunner.installPlugin(new JmxPlugin());
        queryRunner.createCatalog("jmx", "jmx");
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        ElasticsearchConnectorFactory testFactory = new ElasticsearchConnectorFactory();
        installElasticsearchPlugin(address, queryRunner, testFactory, extraConnectorProperties);
        TestingTrinoClient trinoClient = queryRunner.getClient();
        LOG.info("Loading data...");
        client = new RestHighLevelClient(RestClient.builder(HttpHost.create(address.toString())));
        long startTime = System.nanoTime();
        for (TpchTable<?> table : tables) {
            loadTpchTopic(client, trinoClient, table);
        }
        LOG.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS));
        return queryRunner;
    } catch (Exception e) {
        closeAllSuppress(e, queryRunner, client);
        throw e;
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) TestingTrinoClient(io.trino.testing.TestingTrinoClient) JmxPlugin(io.trino.plugin.jmx.JmxPlugin) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 3 with TestingTrinoClient

use of io.trino.testing.TestingTrinoClient in project trino by trinodb.

the class TestServer method testVersionOnCompilerFailedError.

@Test
public void testVersionOnCompilerFailedError() {
    String tableName = "memory.default.test_version_on_compiler_failed";
    try (TestingTrinoClient testingClient = new TestingTrinoClient(server, testSessionBuilder().build())) {
        testingClient.execute("DROP TABLE IF EXISTS " + tableName);
        testingClient.execute("CREATE TABLE " + tableName + " AS SELECT '' as foo");
        // This query is designed to cause a compile failure, and hopefully not run too long.
        // The exact query is not important, just that it causes a failure.
        String array = IntStream.range(0, 254).mapToObj(columnNumber -> "foo").collect(joining(", ", "ARRAY[", "]"));
        String query = "SELECT " + String.join(" || ", Collections.nCopies(10, array)) + "FROM " + tableName;
        checkVersionOnError(query, "TrinoException: Compiler failed(?s:.*)at io.trino.sql.gen.ExpressionCompiler.compile");
    }
}
Also used : QueryId(io.trino.spi.QueryId) QueryError(io.trino.client.QueryError) X_FORWARDED_PORT(com.google.common.net.HttpHeaders.X_FORWARDED_PORT) BasicQueryInfo(io.trino.server.BasicQueryInfo) FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Closeables.closeAll(io.airlift.testing.Closeables.closeAll) QueryResults(io.trino.client.QueryResults) URI(java.net.URI) Collector(java.util.stream.Collector) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Splitter(com.google.common.base.Splitter) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) SEE_OTHER(javax.ws.rs.core.Response.Status.SEE_OTHER) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Builder.prepareHead(io.airlift.http.client.Request.Builder.prepareHead) QUERY_MAX_MEMORY(io.trino.SystemSessionProperties.QUERY_MAX_MEMORY) ImmutableMap(com.google.common.collect.ImmutableMap) OK(javax.ws.rs.core.Response.Status.OK) MemoryPlugin(io.trino.plugin.memory.MemoryPlugin) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) TestingTrinoClient(io.trino.testing.TestingTrinoClient) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Stream(java.util.stream.Stream) Optional(java.util.Optional) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) IntStream(java.util.stream.IntStream) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) Function(java.util.function.Function) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) AbstractSequentialIterator(com.google.common.collect.AbstractSequentialIterator) INCOMPATIBLE_CLIENT(io.trino.spi.StandardErrorCode.INCOMPATIBLE_CLIENT) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) X_FORWARDED_HOST(com.google.common.net.HttpHeaders.X_FORWARDED_HOST) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) Language(org.intellij.lang.annotations.Language) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) HASH_PARTITION_COUNT(io.trino.SystemSessionProperties.HASH_PARTITION_COUNT) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) StatusResponseHandler.createStatusResponseHandler(io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) TimeZoneNotSupportedException(io.trino.spi.type.TimeZoneNotSupportedException) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Collections(java.util.Collections) TRINO_HEADERS(io.trino.client.ProtocolHeaders.TRINO_HEADERS) TestingTrinoClient(io.trino.testing.TestingTrinoClient) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Test(org.testng.annotations.Test)

Aggregations

TestingTrinoClient (io.trino.testing.TestingTrinoClient)3 TpchPlugin (io.trino.plugin.tpch.TpchPlugin)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 AbstractSequentialIterator (com.google.common.collect.AbstractSequentialIterator)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Streams (com.google.common.collect.Streams)1 CONTENT_TYPE (com.google.common.net.HttpHeaders.CONTENT_TYPE)1 X_FORWARDED_HOST (com.google.common.net.HttpHeaders.X_FORWARDED_HOST)1 X_FORWARDED_PORT (com.google.common.net.HttpHeaders.X_FORWARDED_PORT)1 X_FORWARDED_PROTO (com.google.common.net.HttpHeaders.X_FORWARDED_PROTO)1 JsonResponse (io.airlift.http.client.FullJsonResponseHandler.JsonResponse)1 FullJsonResponseHandler.createFullJsonResponseHandler (io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler)1 HttpClient (io.airlift.http.client.HttpClient)1 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)1 Request (io.airlift.http.client.Request)1 Builder.prepareGet (io.airlift.http.client.Request.Builder.prepareGet)1