Search in sources :

Example 1 with MetadataManager

use of io.trino.metadata.MetadataManager in project trino by trinodb.

the class ConnectorManager method createCatalog.

private synchronized void createCatalog(CatalogName catalogName, String connectorName, InternalConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    CatalogClassLoaderSupplier duplicatePluginClassLoaderFactory = new CatalogClassLoaderSupplier(catalogName, factory.getDuplicatePluginClassLoaderFactory(), handleResolver);
    MaterializedConnector connector = new MaterializedConnector(catalogName, createConnector(catalogName, factory.getConnectorFactory(), duplicatePluginClassLoaderFactory, properties), duplicatePluginClassLoaderFactory::destroy);
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaCatalogName(catalogName), new InformationSchemaConnector(catalogName.getCatalogName(), nodeManager, metadataManager, accessControlManager), () -> {
    });
    CatalogName systemId = createSystemTablesCatalogName(catalogName);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new CoordinatorSystemTablesProvider(transactionManager, metadataManager, catalogName.getCatalogName(), new StaticSystemTablesProvider(connector.getSystemTables()));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, catalogName)), () -> {
    });
    SecurityManagement securityManagement = connector.getAccessControl().isPresent() ? CONNECTOR : SYSTEM;
    Catalog catalog = new Catalog(catalogName.getCatalogName(), connector.getCatalogName(), connectorName, connector.getConnector(), securityManagement, informationSchemaConnector.getCatalogName(), informationSchemaConnector.getConnector(), systemConnector.getCatalogName(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getCatalogName());
        removeConnectorInternal(informationSchemaConnector.getCatalogName());
        removeConnectorInternal(connector.getCatalogName());
        throw e;
    }
    connector.getEventListeners().forEach(eventListenerManager::addEventListener);
}
Also used : CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemConnector(io.trino.connector.system.SystemConnector) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) AccessControlManager(io.trino.security.AccessControlManager) ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) TransactionManager(io.trino.transaction.TransactionManager) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) NodeInfo(io.airlift.node.NodeInfo) SplitManager(io.trino.split.SplitManager) ConnectorContext(io.trino.spi.connector.ConnectorContext) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HandleResolver(io.trino.metadata.HandleResolver) PageSorter(io.trino.spi.PageSorter) Map(java.util.Map) MetadataManager(io.trino.metadata.MetadataManager) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ImmutableSet(com.google.common.collect.ImmutableSet) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) ConnectorAccessControl(io.trino.spi.connector.ConnectorAccessControl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PropertyMetadata(io.trino.spi.session.PropertyMetadata) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) List(java.util.List) VersionEmbedder(io.trino.spi.VersionEmbedder) CONNECTOR(io.trino.metadata.Catalog.SecurityManagement.CONNECTOR) Optional(java.util.Optional) SystemConnector(io.trino.connector.system.SystemConnector) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) SystemTable(io.trino.spi.connector.SystemTable) RecordPageSourceProvider(io.trino.split.RecordPageSourceProvider) InternalNodeManager(io.trino.metadata.InternalNodeManager) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Procedure(io.trino.spi.procedure.Procedure) Verify.verify(com.google.common.base.Verify.verify) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) PageIndexerFactory(io.trino.spi.PageIndexerFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) IndexManager(io.trino.index.IndexManager) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Catalog(io.trino.metadata.Catalog) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) SYSTEM(io.trino.metadata.Catalog.SecurityManagement.SYSTEM) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) PluginClassLoader(io.trino.server.PluginClassLoader) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) PageSourceManager(io.trino.split.PageSourceManager) EventListenerManager(io.trino.eventlistener.EventListenerManager) CatalogManager(io.trino.metadata.CatalogManager) TablePropertyManager(io.trino.metadata.TablePropertyManager) ProcedureRegistry(io.trino.metadata.ProcedureRegistry) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) EventListener(io.trino.spi.eventlistener.EventListener) TypeManager(io.trino.spi.type.TypeManager) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) Connector(io.trino.spi.connector.Connector) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) Catalog(io.trino.metadata.Catalog) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider)

Example 2 with MetadataManager

use of io.trino.metadata.MetadataManager 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 MetadataManager (io.trino.metadata.MetadataManager)2 ConnectorFactory (io.trino.spi.connector.ConnectorFactory)2 List (java.util.List)2 Optional (java.util.Optional)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Logger (io.airlift.log.Logger)1 NodeInfo (io.airlift.node.NodeInfo)1 TEST_SESSION (io.trino.SessionTestUtils.TEST_SESSION)1 CatalogName.createInformationSchemaCatalogName (io.trino.connector.CatalogName.createInformationSchemaCatalogName)1 CatalogName.createSystemTablesCatalogName (io.trino.connector.CatalogName.createSystemTablesCatalogName)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)1 InformationSchemaConnector (io.trino.connector.informationschema.InformationSchemaConnector)1 CoordinatorSystemTablesProvider (io.trino.connector.system.CoordinatorSystemTablesProvider)1 StaticSystemTablesProvider (io.trino.connector.system.StaticSystemTablesProvider)1