Skip to content

Commit

Permalink
Extract a method to create testing GlueHiveMetastore
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Dec 20, 2022
1 parent 0d73d10 commit 070d20f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 124 deletions.
5 changes: 0 additions & 5 deletions plugin/trino-delta-lake/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@
<artifactId>units</artifactId>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-glue</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@
*/
package io.trino.plugin.deltalake;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;

import java.util.Optional;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;

/**
* Requires AWS credentials, which can be provided any way supported by the DefaultProviderChain
Expand All @@ -34,14 +27,6 @@ public class TestDeltaLakeSharedGlueMetastoreViews
@Override
protected HiveMetastore createTestMetastore(String dataDirectory)
{
return new GlueHiveMetastore(
HDFS_ENVIRONMENT,
new GlueHiveMetastoreConfig()
.setDefaultWarehouseDir(dataDirectory),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
return createTestingGlueHiveMetastore(dataDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@
*/
package io.trino.plugin.deltalake;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logger;
import io.trino.Session;
import io.trino.plugin.hive.TestingHivePlugin;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
import org.testng.annotations.AfterClass;

import java.nio.file.Path;
import java.util.Optional;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.lang.String.format;

Expand Down Expand Up @@ -72,14 +66,7 @@ protected QueryRunner createQueryRunner()
.put("delta.hive-catalog-name", "hive_with_redirections")
.buildOrThrow());

this.glueMetastore = new GlueHiveMetastore(
HDFS_ENVIRONMENT,
new GlueHiveMetastoreConfig(),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
this.glueMetastore = createTestingGlueHiveMetastore(dataDirectory.toString());
queryRunner.installPlugin(new TestingHivePlugin(glueMetastore));
queryRunner.createCatalog(
"hive_with_redirections",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,20 @@
*/
package io.trino.plugin.deltalake;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logger;
import io.trino.Session;
import io.trino.hdfs.HdfsContext;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
import org.testng.annotations.AfterClass;

import java.io.File;
import java.util.Optional;

import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.deltalake.DeltaLakeConnectorFactory.CONNECTOR_NAME;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.testing.TestingSession.testSessionBuilder;

public class TestDeltaLakeTableWithCustomLocationUsingGlueMetastore
Expand Down Expand Up @@ -64,16 +58,7 @@ protected QueryRunner createQueryRunner()
.put("hive.metastore.glue.default-warehouse-dir", metastoreDir.getPath())
.buildOrThrow());

GlueHiveMetastoreConfig glueConfig = new GlueHiveMetastoreConfig()
.setGlueRegion("us-east-2");
metastore = new GlueHiveMetastore(
HDFS_ENVIRONMENT,
glueConfig,
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
metastore = createTestingGlueHiveMetastore(metastoreDir.getPath());
hdfsContext = new HdfsContext(queryRunner.getDefaultSession().toConnectorSession());

queryRunner.execute("CREATE SCHEMA " + SCHEMA + " WITH (location = '" + metastoreDir.getPath() + "')");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,17 @@
*/
package io.trino.plugin.deltalake.metastore.glue;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import io.trino.plugin.deltalake.BaseDeltaLakeRegisterTableProcedureTest;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;

import java.util.Optional;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;

public class TestDeltaLakeRegisterTableProcedureWithGlue
extends BaseDeltaLakeRegisterTableProcedureTest
{
@Override
protected HiveMetastore createTestMetastore(String dataDirectory)
{
return new GlueHiveMetastore(
HDFS_ENVIRONMENT,
new GlueHiveMetastoreConfig()
.setDefaultWarehouseDir(dataDirectory),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
return createTestingGlueHiveMetastore(dataDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
*/
package io.trino.plugin.deltalake.metastore.glue;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import io.trino.Session;
import io.trino.plugin.deltalake.TestingDeltaLakePlugin;
import io.trino.plugin.deltalake.metastore.TestingDeltaLakeMetastoreModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
Expand All @@ -35,9 +31,8 @@

import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static com.google.inject.util.Modules.EMPTY_MODULE;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.lang.String.format;
Expand All @@ -52,15 +47,7 @@ public class TestDeltaLakeViewsGlueMetastore

private HiveMetastore createTestMetastore(String dataDirectory)
{
return new GlueHiveMetastore(
HDFS_ENVIRONMENT,
new GlueHiveMetastoreConfig()
.setDefaultWarehouseDir(dataDirectory),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
return createTestingGlueHiveMetastore(dataDirectory);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.handlers.AsyncHandler;
import com.amazonaws.handlers.RequestHandler2;
Expand Down Expand Up @@ -60,6 +61,7 @@
import com.amazonaws.services.glue.model.UpdateDatabaseRequest;
import com.amazonaws.services.glue.model.UpdatePartitionRequest;
import com.amazonaws.services.glue.model.UpdateTableRequest;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -68,8 +70,13 @@
import com.google.common.collect.Lists;
import io.airlift.concurrent.MoreFutures;
import io.airlift.log.Logger;
import io.trino.hdfs.DynamicHdfsConfiguration;
import io.trino.hdfs.HdfsConfig;
import io.trino.hdfs.HdfsConfiguration;
import io.trino.hdfs.HdfsConfigurationInitializer;
import io.trino.hdfs.HdfsContext;
import io.trino.hdfs.HdfsEnvironment;
import io.trino.hdfs.authentication.NoHdfsAuthentication;
import io.trino.plugin.hive.HiveColumnStatisticType;
import io.trino.plugin.hive.HiveType;
import io.trino.plugin.hive.PartitionNotFoundException;
Expand Down Expand Up @@ -134,6 +141,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.hive.HiveErrorCode.HIVE_METASTORE_ERROR;
import static io.trino.plugin.hive.aws.AwsCurrentRegionHolder.getCurrentRegionFromEC2Metadata;
import static io.trino.plugin.hive.metastore.MetastoreUtil.makePartitionName;
Expand Down Expand Up @@ -236,6 +244,23 @@ else if (config.getPinGlueClientToCurrentRegion()) {
return asyncGlueClientBuilder.build();
}

@VisibleForTesting
public static GlueHiveMetastore createTestingGlueHiveMetastore(String defaultWarehouseDir)
{
HdfsConfig hdfsConfig = new HdfsConfig();
HdfsConfiguration hdfsConfiguration = new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), ImmutableSet.of());
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication());
return new GlueHiveMetastore(
hdfsEnvironment,
new GlueHiveMetastoreConfig()
.setDefaultWarehouseDir(defaultWarehouseDir),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
}

@Managed
@Flatten
public GlueMetastoreStats getStats()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
*/
package io.trino.plugin.iceberg.catalog.glue;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.services.glue.AWSGlueAsync;
import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logger;
import io.trino.Session;
import io.trino.plugin.hive.metastore.Database;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;
import io.trino.plugin.iceberg.TestingIcebergConnectorFactory;
import io.trino.spi.security.PrincipalType;
import io.trino.testing.AbstractTestQueryFramework;
Expand All @@ -36,9 +33,8 @@
import java.util.Optional;

import static com.google.common.reflect.Reflection.newProxy;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static com.google.inject.util.Modules.EMPTY_MODULE;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.lang.String.format;
Expand Down Expand Up @@ -92,14 +88,7 @@ protected LocalQueryRunner createQueryRunner()
Path dataDirectory = Files.createTempDirectory("iceberg_data");
dataDirectory.toFile().deleteOnExit();

glueHiveMetastore = new GlueHiveMetastore(
HDFS_ENVIRONMENT,
new GlueHiveMetastoreConfig(),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
glueHiveMetastore = createTestingGlueHiveMetastore(dataDirectory.toString());

Database database = Database.builder()
.setDatabaseName(schemaName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
*/
package io.trino.plugin.iceberg.catalog.glue;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.airlift.log.Logger;
import io.trino.Session;
import io.trino.hdfs.DynamicHdfsConfiguration;
import io.trino.hdfs.HdfsConfig;
import io.trino.hdfs.HdfsConfigurationInitializer;
import io.trino.hdfs.HdfsEnvironment;
import io.trino.hdfs.authentication.NoHdfsAuthentication;
import io.trino.plugin.hive.TestingHivePlugin;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.DefaultGlueColumnStatisticsProviderFactory;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig;
import io.trino.plugin.iceberg.BaseSharedMetastoreTest;
import io.trino.plugin.iceberg.IcebergPlugin;
import io.trino.plugin.tpch.TpchPlugin;
Expand All @@ -38,9 +28,8 @@
import org.testng.annotations.AfterClass;

import java.nio.file.Path;
import java.util.Optional;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.plugin.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
import static io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static io.trino.testing.QueryAssertions.copyTpchTables;
Expand Down Expand Up @@ -98,19 +87,7 @@ protected QueryRunner createQueryRunner()
"hive.metastore.glue.default-warehouse-dir", dataDirectory.toString(),
"iceberg.hive-catalog-name", "hive"));

HdfsConfig hdfsConfig = new HdfsConfig();
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(
new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), ImmutableSet.of()),
hdfsConfig,
new NoHdfsAuthentication());
this.glueMetastore = new GlueHiveMetastore(
hdfsEnvironment,
new GlueHiveMetastoreConfig(),
DefaultAWSCredentialsProviderChain.getInstance(),
directExecutor(),
new DefaultGlueColumnStatisticsProviderFactory(directExecutor(), directExecutor()),
Optional.empty(),
table -> true);
this.glueMetastore = createTestingGlueHiveMetastore(dataDirectory.toString());
queryRunner.installPlugin(new TestingHivePlugin(glueMetastore));
queryRunner.createCatalog(HIVE_CATALOG, "hive");
queryRunner.createCatalog(
Expand Down

0 comments on commit 070d20f

Please sign in to comment.