Search in sources :

Example 1 with TestProcedure

use of io.trino.procedure.TestProcedure in project trino by trinodb.

the class TestMockConnector method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(testSessionBuilder().build()).build();
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.createCatalog("tpch", "tpch");
    queryRunner.installPlugin(new MockConnectorPlugin(MockConnectorFactory.builder().withListSchemaNames(connectionSession -> ImmutableList.of("default")).withGetColumns(schemaTableName -> {
        if (schemaTableName.equals(new SchemaTableName("default", "nation"))) {
            return TPCH_NATION_SCHEMA;
        }
        return ImmutableList.of(new ColumnMetadata("nationkey", BIGINT));
    }).withGetTableHandle((session, tableName) -> {
        if (tableName.equals(new SchemaTableName("default", "new_table"))) {
            return null;
        }
        return new MockConnectorTableHandle(tableName);
    }).withGetMaterializedViewProperties(() -> ImmutableList.of(durationProperty("refresh_interval", "Time interval after which materialized view will be refreshed", null, false))).withGetMaterializedViews((session, schemaTablePrefix) -> ImmutableMap.of(new SchemaTableName("default", "test_materialized_view"), 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 Column("nationkey", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of()))).withData(schemaTableName -> {
        if (schemaTableName.equals(new SchemaTableName("default", "nation"))) {
            return TPCH_NATION_DATA;
        }
        throw new UnsupportedOperationException();
    }).withProcedures(ImmutableSet.of(new TestProcedure().get())).withSchemaProperties(() -> ImmutableList.<PropertyMetadata<?>>builder().add(booleanProperty("boolean_schema_property", "description", false, false)).build()).withTableProperties(() -> ImmutableList.<PropertyMetadata<?>>builder().add(integerProperty("integer_table_property", "description", 0, false)).build()).build()));
    queryRunner.createCatalog("mock", "mock");
    return queryRunner;
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test) Column(io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column) PropertyMetadataUtil.durationProperty(io.trino.plugin.base.session.PropertyMetadataUtil.durationProperty) 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) TestProcedure(io.trino.procedure.TestProcedure) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) MockConnectorPlugin(io.trino.connector.MockConnectorPlugin) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TPCH_NATION_DATA(io.trino.connector.MockConnectorEntities.TPCH_NATION_DATA) PropertyMetadata.booleanProperty(io.trino.spi.session.PropertyMetadata.booleanProperty) PropertyMetadata(io.trino.spi.session.PropertyMetadata) TPCH_NATION_SCHEMA(io.trino.connector.MockConnectorEntities.TPCH_NATION_SCHEMA) SchemaTableName(io.trino.spi.connector.SchemaTableName) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) QueryRunner(io.trino.testing.QueryRunner) PropertyMetadata.integerProperty(io.trino.spi.session.PropertyMetadata.integerProperty) Optional(java.util.Optional) Session(io.trino.Session) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TestProcedure(io.trino.procedure.TestProcedure) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) 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) Column(io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) PropertyMetadata(io.trino.spi.session.PropertyMetadata)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Session (io.trino.Session)1 TPCH_NATION_DATA (io.trino.connector.MockConnectorEntities.TPCH_NATION_DATA)1 TPCH_NATION_SCHEMA (io.trino.connector.MockConnectorEntities.TPCH_NATION_SCHEMA)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 MockConnectorPlugin (io.trino.connector.MockConnectorPlugin)1 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)1 PropertyMetadataUtil.durationProperty (io.trino.plugin.base.session.PropertyMetadataUtil.durationProperty)1 TpchPlugin (io.trino.plugin.tpch.TpchPlugin)1 TestProcedure (io.trino.procedure.TestProcedure)1 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)1 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)1 ConnectorMaterializedViewDefinition (io.trino.spi.connector.ConnectorMaterializedViewDefinition)1 Column (io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column)1 SchemaTableName (io.trino.spi.connector.SchemaTableName)1 PropertyMetadata (io.trino.spi.session.PropertyMetadata)1 PropertyMetadata.booleanProperty (io.trino.spi.session.PropertyMetadata.booleanProperty)1 PropertyMetadata.integerProperty (io.trino.spi.session.PropertyMetadata.integerProperty)1