Search in sources :

Example 6 with TpchPlugin

use of io.trino.plugin.tpch.TpchPlugin in project trino by trinodb.

the class TestQueryStateInfoResource method setUp.

@BeforeClass
public void setUp() {
    server = TestingTrinoServer.create();
    server.installPlugin(new TpchPlugin());
    server.createCatalog("tpch", "tpch");
    client = new JettyHttpClient();
    Request request1 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(TRINO_HEADERS.requestUser(), "user1").build();
    queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    Request request2 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(TRINO_HEADERS.requestUser(), "user2").build();
    QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    // queries are started in the background, so they may not all be immediately visible
    long start = System.nanoTime();
    while (Duration.nanosSince(start).compareTo(new Duration(5, MINUTES)) < 0) {
        List<BasicQueryInfo> queryInfos = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).setHeader(TRINO_HEADERS.requestUser(), "unknown").build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        if (queryInfos.size() == 2) {
            if (queryInfos.stream().allMatch(info -> info.getState() == RUNNING)) {
                break;
            }
            List<ErrorCode> errorCodes = queryInfos.stream().filter(info -> info.getState() == FAILED).map(BasicQueryInfo::getErrorCode).collect(toImmutableList());
            if (!errorCodes.isEmpty()) {
                fail("setup queries failed with: " + errorCodes);
            }
        }
    }
}
Also used : TpchPlugin(io.trino.plugin.tpch.TpchPlugin) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Request(io.airlift.http.client.Request) Duration(io.airlift.units.Duration) ErrorCode(io.trino.spi.ErrorCode) QueryResults(io.trino.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with TpchPlugin

use of io.trino.plugin.tpch.TpchPlugin in project trino by trinodb.

the class TestQueryResource method setup.

@BeforeMethod
public void setup() {
    client = new JettyHttpClient();
    server = TestingTrinoServer.create();
    server.installPlugin(new TpchPlugin());
    server.createCatalog("tpch", "tpch");
}
Also used : JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with TpchPlugin

use of io.trino.plugin.tpch.TpchPlugin in project trino by trinodb.

the class H2QueryRunner method createH2QueryRunner.

public static DistributedQueryRunner createH2QueryRunner(Iterable<TpchTable<?>> tables, Map<String, String> properties, Module module) throws Exception {
    DistributedQueryRunner queryRunner = null;
    try {
        queryRunner = DistributedQueryRunner.builder(createSession()).build();
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        createSchema(properties, "tpch");
        queryRunner.installPlugin(new JdbcPlugin("base-jdbc", module));
        queryRunner.createCatalog("jdbc", "base-jdbc", properties);
        copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), tables);
        return queryRunner;
    } catch (Throwable e) {
        closeAllSuppress(e, queryRunner);
        throw e;
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin)

Example 9 with TpchPlugin

use of io.trino.plugin.tpch.TpchPlugin in project trino by trinodb.

the class DeltaLakeQueryRunner method createDeltaLakeQueryRunner.

public static DistributedQueryRunner createDeltaLakeQueryRunner(Map<String, String> extraProperties, Map<String, String> connectorProperties) throws Exception {
    Session session = testSessionBuilder().setCatalog(DELTA_CATALOG).setSchema("tpch").build();
    DistributedQueryRunner.Builder<?> builder = DistributedQueryRunner.builder(session);
    extraProperties.forEach(builder::addExtraProperty);
    DistributedQueryRunner queryRunner = builder.build();
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.createCatalog("tpch", "tpch");
    Path dataDir = queryRunner.getCoordinator().getBaseDataDir().resolve(DELTA_CATALOG);
    connectorProperties = new HashMap<>(ImmutableMap.copyOf(connectorProperties));
    connectorProperties.putIfAbsent("hive.metastore", "file");
    connectorProperties.putIfAbsent("hive.metastore.catalog.dir", dataDir.toString());
    queryRunner.installPlugin(new TestingDeltaLakePlugin());
    queryRunner.createCatalog(DELTA_CATALOG, CONNECTOR_NAME, connectorProperties);
    queryRunner.execute("CREATE SCHEMA tpch");
    return queryRunner;
}
Also used : Path(java.nio.file.Path) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) Session(io.trino.Session)

Example 10 with TpchPlugin

use of io.trino.plugin.tpch.TpchPlugin in project trino by trinodb.

the class BigQueryQueryRunner method createQueryRunner.

public static DistributedQueryRunner createQueryRunner(Map<String, String> extraProperties, Map<String, String> connectorProperties) throws Exception {
    DistributedQueryRunner queryRunner = null;
    try {
        queryRunner = DistributedQueryRunner.builder(createSession()).setExtraProperties(extraProperties).build();
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        connectorProperties = new HashMap<>(ImmutableMap.copyOf(connectorProperties));
        connectorProperties.putIfAbsent("bigquery.views-enabled", "true");
        connectorProperties.putIfAbsent("bigquery.view-expire-duration", "30m");
        queryRunner.installPlugin(new BigQueryPlugin());
        queryRunner.createCatalog("bigquery", "bigquery", connectorProperties);
        return queryRunner;
    } catch (Throwable e) {
        closeAllSuppress(e, queryRunner);
        throw e;
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) TpchPlugin(io.trino.plugin.tpch.TpchPlugin)

Aggregations

TpchPlugin (io.trino.plugin.tpch.TpchPlugin)49 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)39 Session (io.trino.Session)16 BeforeClass (org.testng.annotations.BeforeClass)8 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 QueryRunner (io.trino.testing.QueryRunner)7 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)7 File (java.io.File)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 SchemaTableName (io.trino.spi.connector.SchemaTableName)6 AbstractTestQueryFramework (io.trino.testing.AbstractTestQueryFramework)6 Optional (java.util.Optional)6 Test (org.testng.annotations.Test)6 MockConnectorFactory (io.trino.connector.MockConnectorFactory)5 Plugin (io.trino.spi.Plugin)5 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)3 BlackHolePlugin (io.trino.plugin.blackhole.BlackHolePlugin)3 BIGINT (io.trino.spi.type.BigintType.BIGINT)3