Search in sources :

Example 11 with QueryRunner

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

the class TestKafkaConnectorTest method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    testingKafka = closeAfterClass(TestingKafka.create());
    rawFormatTopic = "test_raw_" + UUID.randomUUID().toString().replaceAll("-", "_");
    headersTopic = "test_header_" + UUID.randomUUID().toString().replaceAll("-", "_");
    Map<SchemaTableName, KafkaTopicDescription> extraTopicDescriptions = ImmutableMap.<SchemaTableName, KafkaTopicDescription>builder().put(new SchemaTableName("default", rawFormatTopic), createDescription(rawFormatTopic, "default", rawFormatTopic, createFieldGroup("raw", ImmutableList.of(createOneFieldDescription("bigint_long", BIGINT, "0", "LONG"), createOneFieldDescription("bigint_int", BIGINT, "8", "INT"), createOneFieldDescription("bigint_short", BIGINT, "12", "SHORT"), createOneFieldDescription("bigint_byte", BIGINT, "14", "BYTE"), createOneFieldDescription("double_double", DOUBLE, "15", "DOUBLE"), createOneFieldDescription("double_float", DOUBLE, "23", "FLOAT"), createOneFieldDescription("varchar_byte", createVarcharType(6), "27:33", "BYTE"), createOneFieldDescription("boolean_long", BOOLEAN, "33", "LONG"), createOneFieldDescription("boolean_int", BOOLEAN, "41", "INT"), createOneFieldDescription("boolean_short", BOOLEAN, "45", "SHORT"), createOneFieldDescription("boolean_byte", BOOLEAN, "47", "BYTE"))))).put(new SchemaTableName("default", headersTopic), new KafkaTopicDescription(headersTopic, Optional.empty(), headersTopic, Optional.empty(), Optional.empty())).putAll(createJsonDateTimeTestTopic()).put(TABLE_INSERT_NEGATIVE_DATE, createDescription(TABLE_INSERT_NEGATIVE_DATE, createOneFieldDescription("key", BIGINT), ImmutableList.of(createOneFieldDescription("dt", DATE, ISO8601.toString())))).put(TABLE_INSERT_CUSTOMER, createDescription(TABLE_INSERT_CUSTOMER, createOneFieldDescription("phone", createVarcharType(15)), ImmutableList.of(createOneFieldDescription("custkey", BIGINT), createOneFieldDescription("acctbal", DOUBLE)))).put(TABLE_INSERT_ARRAY, createDescription(TABLE_INSERT_ARRAY, createOneFieldDescription("a", new ArrayType(DOUBLE)), ImmutableList.of(createOneFieldDescription("b", new ArrayType(DOUBLE))))).put(TABLE_INSERT_UNICODE_1, createDescription(TABLE_INSERT_UNICODE_1, createOneFieldDescription("key", BIGINT), ImmutableList.of(createOneFieldDescription("test", createVarcharType(50))))).put(TABLE_INSERT_UNICODE_2, createDescription(TABLE_INSERT_UNICODE_2, createOneFieldDescription("key", BIGINT), ImmutableList.of(createOneFieldDescription("test", createVarcharType(50))))).put(TABLE_INSERT_UNICODE_3, createDescription(TABLE_INSERT_UNICODE_3, createOneFieldDescription("key", BIGINT), ImmutableList.of(createOneFieldDescription("test", createVarcharType(50))))).put(TABLE_INSERT_HIGHEST_UNICODE, createDescription(TABLE_INSERT_HIGHEST_UNICODE, createOneFieldDescription("key", BIGINT), ImmutableList.of(createOneFieldDescription("test", createVarcharType(50))))).buildOrThrow();
    QueryRunner queryRunner = KafkaQueryRunner.builder(testingKafka).setTables(TpchTable.getTables()).setExtraTopicDescription(extraTopicDescriptions).build();
    return queryRunner;
}
Also used : ArrayType(io.trino.spi.type.ArrayType) SchemaTableName(io.trino.spi.connector.SchemaTableName) QueryRunner(io.trino.testing.QueryRunner)

Example 12 with QueryRunner

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

the class TestMinimalFunctionality method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    testingKafka = closeAfterClass(TestingKafka.create());
    topicName = "test_" + randomUUID().toString().replaceAll("-", "_");
    QueryRunner queryRunner = KafkaQueryRunner.builder(testingKafka).setExtraTopicDescription(ImmutableMap.<SchemaTableName, KafkaTopicDescription>builder().put(createEmptyTopicDescription(topicName, new SchemaTableName("default", topicName))).buildOrThrow()).setExtraKafkaProperties(ImmutableMap.<String, String>builder().put("kafka.messages-per-split", "100").buildOrThrow()).build();
    return queryRunner;
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) QueryRunner(io.trino.testing.QueryRunner)

Example 13 with QueryRunner

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

the class TestQueryTracker method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session defaultSession = testSessionBuilder().setCatalog("mock").setSchema("default").setSystemProperty(QUERY_MAX_PLANNING_TIME, "2s").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession).build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            return ImmutableList.of(MockConnectorFactory.builder().withGetColumns(ignored -> ImmutableList.of(new ColumnMetadata("col", VARCHAR))).withApplyFilter((ignored1, ignored2, ignored3) -> freeze()).build());
        }
    });
    queryRunner.createCatalog("mock", "mock");
    return queryRunner;
}
Also used : AfterClass(org.testng.annotations.AfterClass) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Plugin(io.trino.spi.Plugin) CountDownLatch(java.util.concurrent.CountDownLatch) QUERY_MAX_PLANNING_TIME(io.trino.SystemSessionProperties.QUERY_MAX_PLANNING_TIME) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) QueryRunner(io.trino.testing.QueryRunner) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Session(io.trino.Session) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Session(io.trino.Session) Plugin(io.trino.spi.Plugin)

Example 14 with QueryRunner

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

the class TestRefreshMaterializedView method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setCatalog("mock").setSchema("default").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();
    queryRunner.installPlugin(new MockConnectorPlugin(MockConnectorFactory.builder().withListSchemaNames(connectionSession -> ImmutableList.of("default")).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("nationkey", BIGINT))).withGetTableHandle((connectorSession, tableName) -> new MockConnectorTableHandle(tableName)).withGetMaterializedViews((connectorSession, schemaTablePrefix) -> ImmutableMap.of(new SchemaTableName("default", "delegate_refresh_to_connector"), new ConnectorMaterializedViewDefinition("SELECT nationkey FROM mock.default.test_table", Optional.of(new CatalogSchemaTableName("mock", "default", "test_storage")), Optional.of("mock"), Optional.of("default"), ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("nationkey", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of()))).withDelegateMaterializedViewRefreshToConnector((connectorSession, schemaTableName) -> true).withRefreshMaterializedView(((connectorSession, schemaTableName) -> {
        startRefreshMaterializedView.set(null);
        SettableFuture<Void> refreshMaterializedView = SettableFuture.create();
        finishRefreshMaterializedView.addListener(() -> refreshMaterializedView.set(null), directExecutor());
        addExceptionCallback(refreshMaterializedView, () -> refreshInterrupted.set(null));
        return toCompletableFuture(refreshMaterializedView);
    })).build()));
    queryRunner.createCatalog("mock", "mock");
    return queryRunner;
}
Also used : MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RUNNING(io.trino.execution.QueryState.RUNNING) Test(org.testng.annotations.Test) SettableFuture(com.google.common.util.concurrent.SettableFuture) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MockConnectorPlugin(io.trino.connector.MockConnectorPlugin) MoreFutures.toCompletableFuture(io.airlift.concurrent.MoreFutures.toCompletableFuture) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) MoreFutures.addExceptionCallback(io.airlift.concurrent.MoreFutures.addExceptionCallback) SchemaTableName(io.trino.spi.connector.SchemaTableName) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Futures(com.google.common.util.concurrent.Futures) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) QueryRunner(io.trino.testing.QueryRunner) Optional(java.util.Optional) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Session(io.trino.Session) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) MockConnectorPlugin(io.trino.connector.MockConnectorPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) Session(io.trino.Session)

Example 15 with QueryRunner

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

the class TestSystemConnector method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session defaultSession = testSessionBuilder().setCatalog("mock").setSchema("default").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession).enableBackupCoordinator().build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withGetViews((session, schemaTablePrefix) -> ImmutableMap.of()).withListTables((session, s) -> ImmutableList.of(SCHEMA_TABLE_NAME)).withGetColumns(tableName -> getColumns.apply(tableName)).build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    return queryRunner;
}
Also used : Iterables(com.google.common.collect.Iterables) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MaterializedResult(io.trino.testing.MaterializedResult) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) SettableFuture(com.google.common.util.concurrent.SettableFuture) Function(java.util.function.Function) Duration(io.airlift.units.Duration) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Future(java.util.concurrent.Future) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) MaterializedRow(io.trino.testing.MaterializedRow) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Assert.assertFalse(org.testng.Assert.assertFalse) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) SchemaTableName(io.trino.spi.connector.SchemaTableName) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) ExecutionException(java.util.concurrent.ExecutionException) Plugin(io.trino.spi.Plugin) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) QueryRunner(io.trino.testing.QueryRunner) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) Session(io.trino.Session) Plugin(io.trino.spi.Plugin)

Aggregations

QueryRunner (io.trino.testing.QueryRunner)29 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Test (org.testng.annotations.Test)13 Session (io.trino.Session)12 ImmutableList (com.google.common.collect.ImmutableList)11 Optional (java.util.Optional)11 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)10 SchemaTableName (io.trino.spi.connector.SchemaTableName)9 AbstractTestQueryFramework (io.trino.testing.AbstractTestQueryFramework)9 List (java.util.List)9 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 MockConnectorFactory (io.trino.connector.MockConnectorFactory)7 TpchPlugin (io.trino.plugin.tpch.TpchPlugin)7 MaterializedResult (io.trino.testing.MaterializedResult)7 String.format (java.lang.String.format)7 Map (java.util.Map)6 AfterClass (org.testng.annotations.AfterClass)6 Plugin (io.trino.spi.Plugin)5