Search in sources :

Example 21 with MockConnectorFactory

use of io.trino.connector.MockConnectorFactory in project trino by trinodb.

the class TestErrorThrowableInQuery method createQueryRunner.

@Override
protected DistributedQueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("mock").setSchema("default").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    try {
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.installPlugin(new Plugin() {

            @Override
            public Iterable<ConnectorFactory> getConnectorFactories() {
                SchemaTableName stackOverflowErrorTableName = new SchemaTableName("default", "stack_overflow_during_planning");
                SchemaTableName classFormatErrorTableName = new SchemaTableName("default", "class_format_error_during_planning");
                MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(stackOverflowErrorTableName)).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("test_varchar", createUnboundedVarcharType()), new ColumnMetadata("test_bigint", BIGINT))).withGetTableHandle((session, schemaTableName) -> new MockConnectorTableHandle(schemaTableName)).withApplyProjection((session, handle, projections, assignments) -> {
                    MockConnectorTableHandle mockTableHandle = (MockConnectorTableHandle) handle;
                    if (stackOverflowErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new StackOverflowError("We run out of stack!!!!!!!!!!!");
                    }
                    if (classFormatErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new ClassFormatError("Bad class format!!!!!!!!!!");
                    }
                    throw new TrinoException(NOT_FOUND, "Unknown table: " + mockTableHandle.getTableName());
                }).build();
                return ImmutableList.of(connectorFactory);
            }
        });
        queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    } catch (Exception e) {
        queryRunner.close();
        throw e;
    }
    return queryRunner;
}
Also used : NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test) SchemaTableName(io.trino.spi.connector.SchemaTableName) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Plugin(io.trino.spi.Plugin) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoException(io.trino.spi.TrinoException) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Plugin(io.trino.spi.Plugin) TpchPlugin(io.trino.plugin.tpch.TpchPlugin)

Example 22 with MockConnectorFactory

use of io.trino.connector.MockConnectorFactory 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)

Example 23 with MockConnectorFactory

use of io.trino.connector.MockConnectorFactory in project trino by trinodb.

the class TestMetadataManager method setUp.

@BeforeClass
public void setUp() throws Exception {
    queryRunner = TpchQueryRunnerBuilder.builder().build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            SchemaTableName viewTableName = new SchemaTableName("UPPER_CASE_SCHEMA", "test_view");
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("UPPER_CASE_SCHEMA")).withGetTableHandle((session, schemaTableName) -> {
                if (schemaTableName.equals(viewTableName)) {
                    return null;
                }
                return new MockConnectorTableHandle(schemaTableName);
            }).withListTables((session, schemaNameOrNull) -> ImmutableList.of(new SchemaTableName("UPPER_CASE_SCHEMA", "UPPER_CASE_TABLE"))).withGetViews((session, prefix) -> ImmutableMap.of(viewTableName, getConnectorViewDefinition())).build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("upper_case_schema_catalog", "mock");
    metadataManager = (MetadataManager) queryRunner.getMetadata();
}
Also used : QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RUNNING(io.trino.execution.QueryState.RUNNING) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TpchQueryRunnerBuilder(io.trino.tests.tpch.TpchQueryRunnerBuilder) FAILED(io.trino.execution.QueryState.FAILED) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Slug(io.trino.server.protocol.Slug) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) MetadataManager(io.trino.metadata.MetadataManager) QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) AfterClass(org.testng.annotations.AfterClass) TestingSessionContext(io.trino.testing.TestingSessionContext) DispatchManager(io.trino.dispatcher.DispatchManager) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) SchemaTableName(io.trino.spi.connector.SchemaTableName) TransactionBuilder(io.trino.transaction.TransactionBuilder) Plugin(io.trino.spi.Plugin) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) MockConnectorFactory(io.trino.connector.MockConnectorFactory) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) Plugin(io.trino.spi.Plugin) BeforeClass(org.testng.annotations.BeforeClass)

Example 24 with MockConnectorFactory

use of io.trino.connector.MockConnectorFactory in project trino by trinodb.

the class TestApplyTableScanRedirection method testDoesNotFireForDeleteTableScan.

@Test
public void testDoesNotFireForDeleteTableScan() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        // make the mock connector return a table scan on different table
        ApplyTableScanRedirect applyTableScanRedirect = getMockApplyRedirect(ImmutableMap.of(SOURCE_COLUMN_HANDLE_A, DESTINATION_COLUMN_NAME_A));
        MockConnectorFactory mockFactory = createMockFactory(Optional.of(applyTableScanRedirect));
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
        ruleTester.assertThat(new ApplyTableScanRedirection(ruleTester.getPlannerContext())).on(p -> {
            Symbol column = p.symbol(SOURCE_COLUMN_NAME_A, VARCHAR);
            return p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(column), ImmutableMap.of(column, SOURCE_COLUMN_HANDLE_A), true);
        }).withSession(MOCK_SESSION).doesNotFire();
    }
}
Also used : MockConnectorFactory(io.trino.connector.MockConnectorFactory) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) Symbol(io.trino.sql.planner.Symbol) ApplyTableScanRedirect(io.trino.connector.MockConnectorFactory.ApplyTableScanRedirect) Test(org.testng.annotations.Test)

Example 25 with MockConnectorFactory

use of io.trino.connector.MockConnectorFactory in project trino by trinodb.

the class TestApplyTableScanRedirection method testApplyTableScanRedirection.

@Test
public void testApplyTableScanRedirection() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        // make the mock connector return a table scan on different table
        ApplyTableScanRedirect applyTableScanRedirect = getMockApplyRedirect(ImmutableMap.of(SOURCE_COLUMN_HANDLE_A, DESTINATION_COLUMN_NAME_A));
        MockConnectorFactory mockFactory = createMockFactory(Optional.of(applyTableScanRedirect));
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
        ruleTester.assertThat(new ApplyTableScanRedirection(ruleTester.getPlannerContext())).on(p -> {
            Symbol column = p.symbol(SOURCE_COLUMN_NAME_A, VARCHAR);
            return p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(column), ImmutableMap.of(column, SOURCE_COLUMN_HANDLE_A));
        }).withSession(MOCK_SESSION).matches(tableScan(new MockConnectorTableHandle(DESTINATION_TABLE)::equals, TupleDomain.all(), ImmutableMap.of("DEST_COL", DESTINATION_COLUMN_HANDLE_A::equals)));
    }
}
Also used : MockConnectorFactory(io.trino.connector.MockConnectorFactory) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) Symbol(io.trino.sql.planner.Symbol) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ApplyTableScanRedirect(io.trino.connector.MockConnectorFactory.ApplyTableScanRedirect) Test(org.testng.annotations.Test)

Aggregations

MockConnectorFactory (io.trino.connector.MockConnectorFactory)43 Test (org.testng.annotations.Test)39 RuleTester (io.trino.sql.planner.iterative.rule.test.RuleTester)26 RuleTester.defaultRuleTester (io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester)26 ImmutableList (com.google.common.collect.ImmutableList)23 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)23 SchemaTableName (io.trino.spi.connector.SchemaTableName)23 Symbol (io.trino.sql.planner.Symbol)23 Session (io.trino.Session)22 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)22 ImmutableMap (com.google.common.collect.ImmutableMap)18 Optional (java.util.Optional)17 ColumnHandle (io.trino.spi.connector.ColumnHandle)14 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)14 List (java.util.List)13 BIGINT (io.trino.spi.type.BigintType.BIGINT)12 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)10 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)10