diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeQueryRunner.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeQueryRunner.java index 6b777c759a74..e1649b0b4f4c 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeQueryRunner.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeQueryRunner.java @@ -25,6 +25,7 @@ import io.trino.testing.QueryRunner; import io.trino.tpch.TpchTable; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; @@ -104,14 +105,7 @@ public DistributedQueryRunner build() queryRunner.createCatalog("tpcds", "tpcds"); queryRunner.installPlugin(new TestingDeltaLakePlugin()); - Map deltaProperties = new HashMap<>(this.deltaProperties.buildOrThrow()); - if (!deltaProperties.containsKey("hive.metastore") && !deltaProperties.containsKey("hive.metastore.uri")) { - Path dataDir = queryRunner.getCoordinator().getBaseDataDir().resolve(DELTA_CATALOG); - deltaProperties.put("hive.metastore", "file"); - deltaProperties.put("hive.metastore.catalog.dir", dataDir.toUri().toString()); - } - - queryRunner.createCatalog(catalogName, CONNECTOR_NAME, deltaProperties); + queryRunner.createCatalog(catalogName, CONNECTOR_NAME, deltaProperties.buildOrThrow()); return queryRunner; } @@ -122,19 +116,21 @@ public DistributedQueryRunner build() } } - public static DistributedQueryRunner createDeltaLakeQueryRunner(String catalogName) - throws Exception - { - return createDeltaLakeQueryRunner(catalogName, ImmutableMap.of(), ImmutableMap.of()); - } - public static DistributedQueryRunner createDeltaLakeQueryRunner(String catalogName, Map extraProperties, Map connectorProperties) throws Exception { + Map deltaProperties = new HashMap<>(connectorProperties); + if (!deltaProperties.containsKey("hive.metastore") && !deltaProperties.containsKey("hive.metastore.uri")) { + Path metastoreDirectory = Files.createTempDirectory(catalogName); + metastoreDirectory.toFile().deleteOnExit(); + deltaProperties.put("hive.metastore", "file"); + deltaProperties.put("hive.metastore.catalog.dir", metastoreDirectory.toUri().toString()); + } + DistributedQueryRunner queryRunner = builder(createSession()) .setCatalogName(catalogName) .setExtraProperties(extraProperties) - .setDeltaProperties(connectorProperties) + .setDeltaProperties(deltaProperties) .build(); queryRunner.execute("CREATE SCHEMA IF NOT EXISTS tpch"); @@ -247,14 +243,18 @@ public static class DefaultDeltaLakeQueryRunnerMain public static void main(String[] args) throws Exception { + Path metastoreDirectory = Files.createTempDirectory(DELTA_CATALOG); + metastoreDirectory.toFile().deleteOnExit(); DistributedQueryRunner queryRunner = createDeltaLakeQueryRunner( DELTA_CATALOG, ImmutableMap.of("http-server.http.port", "8080"), - ImmutableMap.of("delta.enable-non-concurrent-writes", "true")); + ImmutableMap.of( + "delta.enable-non-concurrent-writes", "true", + "hive.metastore", "file", + "hive.metastore.catalog.dir", metastoreDirectory.toUri().toString())); - Path baseDirectory = queryRunner.getCoordinator().getBaseDataDir().resolve(DELTA_CATALOG); copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), TpchTable.getTables()); - log.info("Data directory is: %s", baseDirectory); + log.info("Data directory is: %s", metastoreDirectory); Thread.sleep(10); Logger log = Logger.get(DeltaLakeQueryRunner.class); @@ -263,19 +263,18 @@ public static void main(String[] args) } } - public static class DeltaLakeGlueQueryRunnerMain + public static class DeltaLakeExternalQueryRunnerMain { public static void main(String[] args) throws Exception { - // Requires AWS credentials, which can be provided any way supported by the DefaultProviderChain - // See https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default - DistributedQueryRunner queryRunner = createDeltaLakeQueryRunner( - DELTA_CATALOG, - ImmutableMap.of("http-server.http.port", "8080"), - ImmutableMap.of("hive.metastore", "glue")); + // Please set Delta Lake connector properties via VM options. e.g. -Dhive.metastore=glue -D.. + DistributedQueryRunner queryRunner = builder() + .setCatalogName(DELTA_CATALOG) + .setExtraProperties(ImmutableMap.of("http-server.http.port", "8080")) + .build(); - Logger log = Logger.get(DeltaLakeGlueQueryRunnerMain.class); + Logger log = Logger.get(DeltaLakeExternalQueryRunnerMain.class); log.info("======== SERVER STARTED ========"); log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); }