Search in sources :

Example 16 with HiveMetastore

use of io.trino.plugin.hive.metastore.HiveMetastore in project trino by trinodb.

the class TestIcebergOrcMetricsCollection method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setCatalog("iceberg").setSchema("test_schema").setSystemProperty(TASK_CONCURRENCY, "1").setSystemProperty(TASK_WRITER_COUNT, "1").setSystemProperty(MAX_DRIVERS_PER_TASK, "1").setCatalogSessionProperty("iceberg", "orc_string_statistics_limit", Integer.MAX_VALUE + "B").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    File baseDir = queryRunner.getCoordinator().getBaseDataDir().resolve("iceberg_data").toFile();
    HdfsConfig hdfsConfig = new HdfsConfig();
    HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), ImmutableSet.of());
    HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication());
    HiveMetastore metastore = new FileHiveMetastore(new NodeVersion("test_version"), hdfsEnvironment, new MetastoreConfig(), new FileHiveMetastoreConfig().setCatalogDirectory(baseDir.toURI().toString()).setMetastoreUser("test"));
    tableOperationsProvider = new FileMetastoreTableOperationsProvider(new HdfsFileIoProvider(hdfsEnvironment));
    trinoCatalog = new TrinoHiveCatalog(new CatalogName("catalog"), memoizeMetastore(metastore, 1000), hdfsEnvironment, new TestingTypeManager(), tableOperationsProvider, "trino-version", false, false, false);
    queryRunner.installPlugin(new TestingIcebergPlugin(Optional.of(metastore), Optional.empty(), EMPTY_MODULE));
    queryRunner.createCatalog("iceberg", "iceberg");
    queryRunner.installPlugin(new TpchPlugin());
    queryRunner.createCatalog("tpch", "tpch");
    queryRunner.execute("CREATE SCHEMA test_schema");
    return queryRunner;
}
Also used : HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) HdfsConfig(io.trino.plugin.hive.HdfsConfig) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) NodeVersion(io.trino.plugin.hive.NodeVersion) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) FileMetastoreTableOperationsProvider(io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider) TrinoHiveCatalog(io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog) CatalogName(io.trino.plugin.base.CatalogName) File(java.io.File) TestingTypeManager(io.trino.spi.type.TestingTypeManager) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Session(io.trino.Session)

Example 17 with HiveMetastore

use of io.trino.plugin.hive.metastore.HiveMetastore in project trino by trinodb.

the class TestIcebergProjectionPushdownPlans method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session session = testSessionBuilder().setCatalog(CATALOG).setSchema(SCHEMA).build();
    metastoreDir = Files.createTempDir();
    HiveMetastore metastore = createTestingFileHiveMetastore(metastoreDir);
    LocalQueryRunner queryRunner = LocalQueryRunner.create(session);
    queryRunner.createCatalog(CATALOG, new TestingIcebergConnectorFactory(Optional.of(metastore), Optional.empty(), EMPTY_MODULE), ImmutableMap.of());
    Database database = Database.builder().setDatabaseName(SCHEMA).setOwnerName(Optional.of("public")).setOwnerType(Optional.of(PrincipalType.ROLE)).build();
    metastore.createDatabase(database);
    return queryRunner;
}
Also used : HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore.createTestingFileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore) Database(io.trino.plugin.hive.metastore.Database) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Example 18 with HiveMetastore

use of io.trino.plugin.hive.metastore.HiveMetastore in project trino by trinodb.

the class TestIcebergMergeAppend method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    DistributedQueryRunner queryRunner = IcebergQueryRunner.createIcebergQueryRunner();
    HdfsConfig hdfsConfig = new HdfsConfig();
    HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), ImmutableSet.of());
    HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication());
    File baseDir = queryRunner.getCoordinator().getBaseDataDir().resolve("iceberg_data").toFile();
    HiveMetastore metastore = new FileHiveMetastore(new NodeVersion("testversion"), hdfsEnvironment, new MetastoreConfig(), new FileHiveMetastoreConfig().setCatalogDirectory(baseDir.toURI().toString()).setMetastoreUser("test"));
    tableOperationsProvider = new FileMetastoreTableOperationsProvider(new HdfsFileIoProvider(hdfsEnvironment));
    trinoCatalog = new TrinoHiveCatalog(new CatalogName("catalog"), memoizeMetastore(metastore, 1000), hdfsEnvironment, new TestingTypeManager(), tableOperationsProvider, "trino-version", false, false, false);
    return queryRunner;
}
Also used : HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) HdfsConfig(io.trino.plugin.hive.HdfsConfig) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) NodeVersion(io.trino.plugin.hive.NodeVersion) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) FileMetastoreTableOperationsProvider(io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider) TrinoHiveCatalog(io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog) CatalogName(io.trino.plugin.base.CatalogName) File(java.io.File) TestingTypeManager(io.trino.spi.type.TestingTypeManager)

Example 19 with HiveMetastore

use of io.trino.plugin.hive.metastore.HiveMetastore in project trino by trinodb.

the class TestIcebergMetastoreAccessOperations method createQueryRunner.

@Override
protected DistributedQueryRunner createQueryRunner() throws Exception {
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(TEST_SESSION).build();
    File baseDir = queryRunner.getCoordinator().getBaseDataDir().resolve("iceberg_data").toFile();
    HdfsConfig hdfsConfig = new HdfsConfig();
    HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), ImmutableSet.of());
    HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication());
    HiveMetastore hiveMetastore = new FileHiveMetastore(new NodeVersion("testversion"), hdfsEnvironment, new MetastoreConfig(), new FileHiveMetastoreConfig().setCatalogDirectory(baseDir.toURI().toString()).setMetastoreUser("test"));
    metastore = new CountingAccessFileHiveMetastore(hiveMetastore);
    queryRunner.installPlugin(new TestingIcebergPlugin(Optional.of(metastore), Optional.empty(), EMPTY_MODULE));
    queryRunner.createCatalog("iceberg", "iceberg");
    queryRunner.execute("CREATE SCHEMA test_schema");
    return queryRunner;
}
Also used : HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) HdfsConfig(io.trino.plugin.hive.HdfsConfig) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) NodeVersion(io.trino.plugin.hive.NodeVersion) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) File(java.io.File)

Example 20 with HiveMetastore

use of io.trino.plugin.hive.metastore.HiveMetastore in project trino by trinodb.

the class TestDeltaLakePerTransactionMetastoreCache method createQueryRunner.

private DistributedQueryRunner createQueryRunner(boolean enablePerTransactionHiveMetastoreCaching) throws Exception {
    boolean createdDeltaLake = false;
    if (dockerizedMinioDataLake == null) {
        // share environment between testcases to speed things up
        dockerizedMinioDataLake = createDockerizedMinioDataLakeForDeltaLake(BUCKET_NAME);
        createdDeltaLake = true;
    }
    Session session = testSessionBuilder().setCatalog(DELTA_CATALOG).setSchema("default").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            return ImmutableList.of(new ConnectorFactory() {

                @Override
                public String getName() {
                    return TEST_DELTA_CONNECTOR_NAME;
                }

                @Override
                public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
                    return InternalDeltaLakeConnectorFactory.createConnector(catalogName, config, context, new AbstractConfigurationAwareModule() {

                        @Override
                        protected void setup(Binder binder) {
                            newOptionalBinder(binder, ThriftMetastoreClientFactory.class).setDefault().to(DefaultThriftMetastoreClientFactory.class).in(Scopes.SINGLETON);
                            binder.bind(MetastoreLocator.class).to(StaticMetastoreLocator.class).in(Scopes.SINGLETON);
                            configBinder(binder).bindConfig(StaticMetastoreConfig.class);
                            configBinder(binder).bindConfig(ThriftMetastoreConfig.class);
                            binder.bind(ThriftMetastore.class).to(ThriftHiveMetastore.class).in(Scopes.SINGLETON);
                            newExporter(binder).export(ThriftMetastore.class).as((generator) -> generator.generatedNameOf(ThriftHiveMetastore.class));
                            install(new ThriftMetastoreAuthenticationModule());
                            binder.bind(Boolean.class).annotatedWith(HideNonDeltaLakeTables.class).toInstance(false);
                            binder.bind(BridgingHiveMetastoreFactory.class).in(Scopes.SINGLETON);
                        }

                        @Provides
                        @Singleton
                        @RawHiveMetastoreFactory
                        public HiveMetastoreFactory getCountingHiveMetastoreFactory(BridgingHiveMetastoreFactory bridgingHiveMetastoreFactory) {
                            return new HiveMetastoreFactory() {

                                @Override
                                public boolean isImpersonationEnabled() {
                                    return false;
                                }

                                @Override
                                public HiveMetastore createMetastore(Optional<ConnectorIdentity> identity) {
                                    HiveMetastore bridgingHiveMetastore = bridgingHiveMetastoreFactory.createMetastore(identity);
                                    // bind HiveMetastore which counts method executions
                                    return Reflection.newProxy(HiveMetastore.class, (proxy, method, args) -> {
                                        String methodName = method.getName();
                                        long count = hiveMetastoreInvocationCounts.getOrDefault(methodName, 0L);
                                        hiveMetastoreInvocationCounts.put(methodName, count + 1);
                                        return method.invoke(bridgingHiveMetastore, args);
                                    });
                                }
                            };
                        }
                    });
                }
            });
        }
    });
    ImmutableMap.Builder<String, String> deltaLakeProperties = ImmutableMap.builder();
    deltaLakeProperties.put("hive.metastore.uri", dockerizedMinioDataLake.getTestingHadoop().getMetastoreAddress());
    deltaLakeProperties.put("hive.s3.aws-access-key", MINIO_ACCESS_KEY);
    deltaLakeProperties.put("hive.s3.aws-secret-key", MINIO_SECRET_KEY);
    deltaLakeProperties.put("hive.s3.endpoint", dockerizedMinioDataLake.getMinioAddress());
    deltaLakeProperties.put("hive.s3.path-style-access", "true");
    // use test value so we do not get clash with default bindings)
    deltaLakeProperties.put("hive.metastore", "test");
    if (!enablePerTransactionHiveMetastoreCaching) {
        // almost disable the cache; 0 is not allowed as config property value
        deltaLakeProperties.put("hive.per-transaction-metastore-cache-maximum-size", "1");
    }
    queryRunner.createCatalog(DELTA_CATALOG, TEST_DELTA_CONNECTOR_NAME, deltaLakeProperties.buildOrThrow());
    if (createdDeltaLake) {
        List<TpchTable<? extends TpchEntity>> tpchTables = List.of(TpchTable.NATION, TpchTable.REGION);
        tpchTables.forEach(table -> {
            String tableName = table.getTableName();
            dockerizedMinioDataLake.copyResources("io/trino/plugin/deltalake/testing/resources/databricks/" + tableName, tableName);
            queryRunner.execute(format("CREATE TABLE %s.%s.%s (dummy int) WITH (location = 's3://%s/%3$s')", DELTA_CATALOG, "default", tableName, BUCKET_NAME));
        });
    }
    return queryRunner;
}
Also used : BridgingHiveMetastoreFactory(io.trino.plugin.hive.metastore.thrift.BridgingHiveMetastoreFactory) DELTA_CATALOG(io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MINIO_SECRET_KEY(io.trino.plugin.deltalake.util.MinioContainer.MINIO_SECRET_KEY) Test(org.testng.annotations.Test) ConnectorContext(io.trino.spi.connector.ConnectorContext) Singleton(javax.inject.Singleton) StaticMetastoreConfig(io.trino.plugin.hive.metastore.thrift.StaticMetastoreConfig) MINIO_ACCESS_KEY(io.trino.plugin.deltalake.util.MinioContainer.MINIO_ACCESS_KEY) ThriftMetastoreClientFactory(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreClientFactory) HiveMetastoreFactory(io.trino.plugin.hive.metastore.HiveMetastoreFactory) AbstractConfigurationAwareModule(io.airlift.configuration.AbstractConfigurationAwareModule) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) DockerizedMinioDataLake(io.trino.plugin.deltalake.util.DockerizedMinioDataLake) Map(java.util.Map) ExportBinder.newExporter(org.weakref.jmx.guice.ExportBinder.newExporter) DefaultThriftMetastoreClientFactory(io.trino.plugin.hive.metastore.thrift.DefaultThriftMetastoreClientFactory) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) OptionalBinder.newOptionalBinder(com.google.inject.multibindings.OptionalBinder.newOptionalBinder) TpchEntity(io.trino.tpch.TpchEntity) TpchTable(io.trino.tpch.TpchTable) StaticMetastoreLocator(io.trino.plugin.hive.metastore.thrift.StaticMetastoreLocator) AfterClass(org.testng.annotations.AfterClass) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) ImmutableMap(com.google.common.collect.ImmutableMap) ThriftHiveMetastore(io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Reflection(com.google.common.reflect.Reflection) ThriftMetastoreAuthenticationModule(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationModule) Scopes(com.google.inject.Scopes) RawHiveMetastoreFactory(io.trino.plugin.hive.metastore.RawHiveMetastoreFactory) String.format(java.lang.String.format) Plugin(io.trino.spi.Plugin) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Provides(com.google.inject.Provides) DeltaLakeDockerizedMinioDataLake.createDockerizedMinioDataLakeForDeltaLake(io.trino.plugin.deltalake.DeltaLakeDockerizedMinioDataLake.createDockerizedMinioDataLakeForDeltaLake) MetastoreLocator(io.trino.plugin.hive.metastore.thrift.MetastoreLocator) ThriftMetastore(io.trino.plugin.hive.metastore.thrift.ThriftMetastore) ThriftMetastoreConfig(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreConfig) Optional(java.util.Optional) ConfigBinder.configBinder(io.airlift.configuration.ConfigBinder.configBinder) Session(io.trino.Session) Connector(io.trino.spi.connector.Connector) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) RawHiveMetastoreFactory(io.trino.plugin.hive.metastore.RawHiveMetastoreFactory) StaticMetastoreLocator(io.trino.plugin.hive.metastore.thrift.StaticMetastoreLocator) MetastoreLocator(io.trino.plugin.hive.metastore.thrift.MetastoreLocator) TpchTable(io.trino.tpch.TpchTable) ThriftMetastoreConfig(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreConfig) Binder(com.google.inject.Binder) OptionalBinder.newOptionalBinder(com.google.inject.multibindings.OptionalBinder.newOptionalBinder) ConfigBinder.configBinder(io.airlift.configuration.ConfigBinder.configBinder) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) ConnectorContext(io.trino.spi.connector.ConnectorContext) AbstractConfigurationAwareModule(io.airlift.configuration.AbstractConfigurationAwareModule) ThriftMetastoreAuthenticationModule(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationModule) BridgingHiveMetastoreFactory(io.trino.plugin.hive.metastore.thrift.BridgingHiveMetastoreFactory) HiveMetastoreFactory(io.trino.plugin.hive.metastore.HiveMetastoreFactory) RawHiveMetastoreFactory(io.trino.plugin.hive.metastore.RawHiveMetastoreFactory) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) ThriftHiveMetastore(io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastore) ThriftMetastore(io.trino.plugin.hive.metastore.thrift.ThriftMetastore) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) Provides(com.google.inject.Provides) TpchEntity(io.trino.tpch.TpchEntity) ImmutableMap(com.google.common.collect.ImmutableMap) BridgingHiveMetastoreFactory(io.trino.plugin.hive.metastore.thrift.BridgingHiveMetastoreFactory) Singleton(javax.inject.Singleton) StaticMetastoreConfig(io.trino.plugin.hive.metastore.thrift.StaticMetastoreConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Session(io.trino.Session) Plugin(io.trino.spi.Plugin)

Aggregations

HiveMetastore (io.trino.plugin.hive.metastore.HiveMetastore)23 File (java.io.File)10 MetastoreConfig (io.trino.plugin.hive.metastore.MetastoreConfig)9 NoHdfsAuthentication (io.trino.plugin.hive.authentication.NoHdfsAuthentication)8 FileHiveMetastore.createTestingFileHiveMetastore (io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore)8 Optional (java.util.Optional)8 Map (java.util.Map)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 HdfsConfig (io.trino.plugin.hive.HdfsConfig)6 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)6 HdfsConfigurationInitializer (io.trino.plugin.hive.HdfsConfigurationInitializer)6 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)6 HiveHdfsConfiguration (io.trino.plugin.hive.HiveHdfsConfiguration)6 NodeVersion (io.trino.plugin.hive.NodeVersion)6 List (java.util.List)6 Test (org.testng.annotations.Test)6 Session (io.trino.Session)5 CatalogName (io.trino.plugin.base.CatalogName)5 ThriftHiveMetastore (io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastore)5