Search in sources :

Example 1 with DeltaLakeMetastoreModule

use of io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule in project trino by trinodb.

the class InternalDeltaLakeConnectorFactory method createConnector.

@VisibleForTesting
public static Connector createConnector(String catalogName, Map<String, String> config, ConnectorContext context, Module extraModule) {
    ClassLoader classLoader = InternalDeltaLakeConnectorFactory.class.getClassLoader();
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new EventModule(), new MBeanModule(), new JsonModule(), new MBeanServerModule(), new HiveHdfsModule(), new HiveS3Module(), new HiveAzureModule(), new HdfsAuthenticationModule(), new CatalogNameModule(catalogName), new DeltaLakeMetastoreModule(), new DeltaLakeModule(), binder -> {
            binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
            binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
            newSetBinder(binder, EventListener.class);
        }, binder -> bindSessionPropertiesProvider(binder, DeltaLakeSessionProperties.class), extraModule);
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
        ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
        ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
        ConnectorPageSinkProvider connectorPageSink = injector.getInstance(ConnectorPageSinkProvider.class);
        ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
        Set<SessionPropertiesProvider> sessionPropertiesProviders = injector.getInstance(Key.get(new TypeLiteral<Set<SessionPropertiesProvider>>() {
        }));
        DeltaLakeTableProperties deltaLakeTableProperties = injector.getInstance(DeltaLakeTableProperties.class);
        DeltaLakeAnalyzeProperties deltaLakeAnalyzeProperties = injector.getInstance(DeltaLakeAnalyzeProperties.class);
        DeltaLakeTransactionManager transactionManager = injector.getInstance(DeltaLakeTransactionManager.class);
        Set<EventListener> eventListeners = injector.getInstance(Key.get(new TypeLiteral<Set<EventListener>>() {
        })).stream().map(listener -> new ClassLoaderSafeEventListener(listener, classLoader)).collect(toImmutableSet());
        Set<Procedure> procedures = injector.getInstance(Key.get(new TypeLiteral<Set<Procedure>>() {
        }));
        Set<TableProcedureMetadata> tableProcedures = injector.getInstance(Key.get(new TypeLiteral<Set<TableProcedureMetadata>>() {
        }));
        return new DeltaLakeConnector(lifeCycleManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(connectorPageSink, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), ImmutableSet.of(), procedures, tableProcedures, sessionPropertiesProviders, DeltaLakeSchemaProperties.SCHEMA_PROPERTIES, deltaLakeTableProperties.getTableProperties(), deltaLakeAnalyzeProperties.getAnalyzeProperties(), eventListeners, transactionManager);
    }
}
Also used : Module(com.google.inject.Module) HiveAzureModule(io.trino.plugin.hive.azure.HiveAzureModule) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) MBeanModule(org.weakref.jmx.guice.MBeanModule) NodeManager(io.trino.spi.NodeManager) Key(com.google.inject.Key) HiveHdfsModule(io.trino.plugin.hive.HiveHdfsModule) ConnectorContext(io.trino.spi.connector.ConnectorContext) ClassLoaderSafeConnectorSplitManager(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager) EventModule(io.airlift.event.client.EventModule) HiveS3Module(io.trino.plugin.hive.s3.HiveS3Module) SessionPropertiesProvider(io.trino.plugin.base.session.SessionPropertiesProvider) Binder(com.google.inject.Binder) Procedure(io.trino.spi.procedure.Procedure) NodeVersion(io.trino.plugin.hive.NodeVersion) PageIndexerFactory(io.trino.spi.PageIndexerFactory) Map(java.util.Map) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ClassLoaderSafeConnectorPageSinkProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ImmutableSet(com.google.common.collect.ImmutableSet) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Set(java.util.Set) CatalogNameModule(io.trino.plugin.base.CatalogNameModule) Scopes(com.google.inject.Scopes) CatalogName(io.trino.plugin.base.CatalogName) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) Injector(com.google.inject.Injector) ClassLoaderSafeNodePartitioningProvider(io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider) ClassLoaderSafeConnectorPageSourceProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider) ClassLoaderSafeEventListener(io.trino.plugin.base.classloader.ClassLoaderSafeEventListener) HdfsAuthenticationModule(io.trino.plugin.hive.authentication.HdfsAuthenticationModule) DeltaLakeMetastoreModule(io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule) Bootstrap(io.airlift.bootstrap.Bootstrap) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) EventListener(io.trino.spi.eventlistener.EventListener) TypeLiteral(com.google.inject.TypeLiteral) TypeManager(io.trino.spi.type.TypeManager) MBeanServerModule(io.trino.plugin.base.jmx.MBeanServerModule) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) JsonModule(io.airlift.json.JsonModule) Connector(io.trino.spi.connector.Connector) MBeanModule(org.weakref.jmx.guice.MBeanModule) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) EventModule(io.airlift.event.client.EventModule) ClassLoaderSafeEventListener(io.trino.plugin.base.classloader.ClassLoaderSafeEventListener) CatalogNameModule(io.trino.plugin.base.CatalogNameModule) SessionPropertiesProvider(io.trino.plugin.base.session.SessionPropertiesProvider) NodeVersion(io.trino.plugin.hive.NodeVersion) ClassLoaderSafeConnectorPageSourceProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) DeltaLakeMetastoreModule(io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) Bootstrap(io.airlift.bootstrap.Bootstrap) Procedure(io.trino.spi.procedure.Procedure) ClassLoaderSafeEventListener(io.trino.plugin.base.classloader.ClassLoaderSafeEventListener) EventListener(io.trino.spi.eventlistener.EventListener) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) ClassLoaderSafeNodePartitioningProvider(io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider) HiveAzureModule(io.trino.plugin.hive.azure.HiveAzureModule) ClassLoaderSafeConnectorPageSinkProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider) HdfsAuthenticationModule(io.trino.plugin.hive.authentication.HdfsAuthenticationModule) JsonModule(io.airlift.json.JsonModule) PageIndexerFactory(io.trino.spi.PageIndexerFactory) HiveS3Module(io.trino.plugin.hive.s3.HiveS3Module) NodeManager(io.trino.spi.NodeManager) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) ClassLoaderSafeConnectorPageSinkProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) ClassLoaderSafeConnectorSplitManager(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) ClassLoaderSafeConnectorPageSourceProvider(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider) MBeanServerModule(io.trino.plugin.base.jmx.MBeanServerModule) HiveHdfsModule(io.trino.plugin.hive.HiveHdfsModule) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ClassLoaderSafeConnectorSplitManager(io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager) TypeManager(io.trino.spi.type.TypeManager) CatalogName(io.trino.plugin.base.CatalogName) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DeltaLakeMetastoreModule

use of io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule in project trino by trinodb.

the class TestDeltaLakeGlueMetastore method setUp.

@BeforeClass
public void setUp() {
    tempDir = Files.createTempDir();
    String temporaryLocation = tempDir.toURI().toString();
    Map<String, String> config = ImmutableMap.<String, String>builder().put("hive.metastore", "glue").put("delta.hide-non-delta-lake-tables", "true").buildOrThrow();
    Bootstrap app = new Bootstrap(// connector dependencies
    new JsonModule(), binder -> {
        ConnectorContext context = new TestingConnectorContext();
        binder.bind(CatalogName.class).toInstance(new CatalogName("test"));
        binder.bind(TypeManager.class).toInstance(context.getTypeManager());
        binder.bind(NodeManager.class).toInstance(context.getNodeManager());
        binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
        binder.bind(NodeVersion.class).toInstance(new NodeVersion("test_version"));
    }, // connector modules
    new DeltaLakeMetastoreModule(), new DeltaLakeModule(), // test setup
    binder -> {
        binder.bind(HdfsEnvironment.class).toInstance(HDFS_ENVIRONMENT);
    });
    Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    metastoreClient = injector.getInstance(GlueHiveMetastore.class);
    metadataFactory = injector.getInstance(DeltaLakeMetadataFactory.class);
    session = TestingConnectorSession.builder().setPropertyMetadata(injector.getInstance(DeltaLakeSessionProperties.class).getSessionProperties()).build();
    databaseName = "test_delta_glue" + randomName();
    metastoreClient.createDatabase(Database.builder().setDatabaseName(databaseName).setOwnerName(Optional.of("public")).setOwnerType(Optional.of(ROLE)).setLocation(Optional.of(temporaryLocation)).build());
}
Also used : DeltaLakeModule(io.trino.plugin.deltalake.DeltaLakeModule) TestingConnectorContext(io.trino.testing.TestingConnectorContext) DeltaLakeMetadataFactory(io.trino.plugin.deltalake.DeltaLakeMetadataFactory) JsonModule(io.airlift.json.JsonModule) PageIndexerFactory(io.trino.spi.PageIndexerFactory) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) GlueHiveMetastore(io.trino.plugin.hive.metastore.glue.GlueHiveMetastore) NodeVersion(io.trino.plugin.hive.NodeVersion) NodeManager(io.trino.spi.NodeManager) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) ConnectorContext(io.trino.spi.connector.ConnectorContext) TestingConnectorContext(io.trino.testing.TestingConnectorContext) DeltaLakeMetastoreModule(io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeManager(io.trino.spi.type.TypeManager) CatalogName(io.trino.plugin.base.CatalogName) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with DeltaLakeMetastoreModule

use of io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule in project trino by trinodb.

the class TestDeltaLakeMetadata method setUp.

@BeforeClass
public void setUp() throws IOException {
    temporaryCatalogDirectory = createTempDirectory("HiveCatalog").toFile();
    Map<String, String> config = ImmutableMap.<String, String>builder().put("hive.metastore", "file").put("hive.metastore.catalog.dir", temporaryCatalogDirectory.getPath()).buildOrThrow();
    Bootstrap app = new Bootstrap(// connector dependencies
    new JsonModule(), binder -> {
        ConnectorContext context = new TestingConnectorContext();
        binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
        binder.bind(CatalogName.class).toInstance(new CatalogName("test"));
        binder.bind(TypeManager.class).toInstance(context.getTypeManager());
        binder.bind(NodeManager.class).toInstance(context.getNodeManager());
        binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
    }, // connector modules
    new DeltaLakeMetastoreModule(), new DeltaLakeModule(), // test setup
    binder -> {
        binder.bind(HdfsEnvironment.class).toInstance(HDFS_ENVIRONMENT);
    }, new AbstractModule() {

        @Provides
        public DeltaLakeMetastore getDeltaLakeMetastore(@RawHiveMetastoreFactory HiveMetastoreFactory hiveMetastoreFactory, TransactionLogAccess transactionLogAccess, TypeManager typeManager, CachingDeltaLakeStatisticsAccess statistics) {
            return new HiveMetastoreBackedDeltaLakeMetastore(hiveMetastoreFactory.createMetastore(Optional.empty()), transactionLogAccess, typeManager, statistics);
        }
    });
    Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
    deltaLakeMetadataFactory = injector.getInstance(DeltaLakeMetadataFactory.class);
    injector.getInstance(DeltaLakeMetastore.class).createDatabase(Database.builder().setDatabaseName(DATABASE_NAME).setOwnerName(Optional.of("test")).setOwnerType(Optional.of(USER)).setLocation(Optional.empty()).build());
}
Also used : HiveMetastoreFactory(io.trino.plugin.hive.metastore.HiveMetastoreFactory) RawHiveMetastoreFactory(io.trino.plugin.hive.metastore.RawHiveMetastoreFactory) TransactionLogAccess(io.trino.plugin.deltalake.transactionlog.TransactionLogAccess) TestingConnectorContext(io.trino.testing.TestingConnectorContext) Provides(com.google.inject.Provides) DeltaLakeMetastore(io.trino.plugin.deltalake.metastore.DeltaLakeMetastore) HiveMetastoreBackedDeltaLakeMetastore(io.trino.plugin.deltalake.metastore.HiveMetastoreBackedDeltaLakeMetastore) JsonModule(io.airlift.json.JsonModule) PageIndexerFactory(io.trino.spi.PageIndexerFactory) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) AbstractModule(com.google.inject.AbstractModule) NodeVersion(io.trino.plugin.hive.NodeVersion) NodeManager(io.trino.spi.NodeManager) HiveMetastoreBackedDeltaLakeMetastore(io.trino.plugin.deltalake.metastore.HiveMetastoreBackedDeltaLakeMetastore) Injector(com.google.inject.Injector) ConnectorContext(io.trino.spi.connector.ConnectorContext) TestingConnectorContext(io.trino.testing.TestingConnectorContext) DeltaLakeMetastoreModule(io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeManager(io.trino.spi.type.TypeManager) CatalogName(io.trino.plugin.base.CatalogName) CachingDeltaLakeStatisticsAccess(io.trino.plugin.deltalake.statistics.CachingDeltaLakeStatisticsAccess) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Injector (com.google.inject.Injector)3 Bootstrap (io.airlift.bootstrap.Bootstrap)3 JsonModule (io.airlift.json.JsonModule)3 CatalogName (io.trino.plugin.base.CatalogName)3 DeltaLakeMetastoreModule (io.trino.plugin.deltalake.metastore.DeltaLakeMetastoreModule)3 NodeVersion (io.trino.plugin.hive.NodeVersion)3 NodeManager (io.trino.spi.NodeManager)3 PageIndexerFactory (io.trino.spi.PageIndexerFactory)3 ConnectorContext (io.trino.spi.connector.ConnectorContext)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)2 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)2 TypeManager (io.trino.spi.type.TypeManager)2 TestingConnectorContext (io.trino.testing.TestingConnectorContext)2 BeforeClass (org.testng.annotations.BeforeClass)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 AbstractModule (com.google.inject.AbstractModule)1 Binder (com.google.inject.Binder)1 Key (com.google.inject.Key)1