Search in sources :

Example 26 with ConnectorFactory

use of io.trino.spi.connector.ConnectorFactory 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 27 with ConnectorFactory

use of io.trino.spi.connector.ConnectorFactory 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 28 with ConnectorFactory

use of io.trino.spi.connector.ConnectorFactory 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 29 with ConnectorFactory

use of io.trino.spi.connector.ConnectorFactory 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 30 with ConnectorFactory

use of io.trino.spi.connector.ConnectorFactory in project TiBigData by tidb-incubator.

the class ConnectorsPluginTest method testCreateConnector.

@Test
public void testCreateConnector() {
    Plugin plugin = new ConnectorsPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    factory.create("tidb", ConfigUtils.getProperties(), new TestingConnectorContext());
}
Also used : ConnectorFactory(io.trino.spi.connector.ConnectorFactory) ConnectorsPlugin(io.tidb.bigdata.trino.ConnectorsPlugin) TestingConnectorContext(io.trino.testing.TestingConnectorContext) Plugin(io.trino.spi.Plugin) ConnectorsPlugin(io.tidb.bigdata.trino.ConnectorsPlugin) Test(org.junit.Test) IntegrationTest(io.tidb.bigdata.test.IntegrationTest)

Aggregations

ConnectorFactory (io.trino.spi.connector.ConnectorFactory)66 Test (org.testng.annotations.Test)61 TestingConnectorContext (io.trino.testing.TestingConnectorContext)56 Plugin (io.trino.spi.Plugin)29 Connector (io.trino.spi.connector.Connector)13 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 Session (io.trino.Session)7 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)7 MockConnectorFactory (io.trino.connector.MockConnectorFactory)6 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)6 SchemaTableName (io.trino.spi.connector.SchemaTableName)5 AbstractTestQueryFramework (io.trino.testing.AbstractTestQueryFramework)5 List (java.util.List)5 Optional (java.util.Optional)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 QueryRunner (io.trino.testing.QueryRunner)4 Path (java.nio.file.Path)4 ResourceGroupManagerPlugin (io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)3 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)3