Skip to content

Commit

Permalink
Build catalog-specific properties for IcebergQueryRunner w static method
Browse files Browse the repository at this point in the history
Signed-off-by: kiersten-stokes <[email protected]>
  • Loading branch information
kiersten-stokes committed Oct 20, 2023
1 parent 16cb531 commit d117ff8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.facebook.airlift.log.Logging;
import com.facebook.presto.Session;
import com.facebook.presto.connector.jmx.JmxPlugin;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.tests.DistributedQueryRunner;
import com.facebook.presto.tpch.TpchPlugin;
import com.google.common.collect.ImmutableMap;
Expand All @@ -27,6 +28,8 @@
import java.util.Map;
import java.util.OptionalInt;

import static com.facebook.presto.iceberg.CatalogType.HIVE;
import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tests.QueryAssertions.copyTpchTables;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;
Expand Down Expand Up @@ -100,14 +103,14 @@ public static DistributedQueryRunner createIcebergQueryRunner(
queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");

Path dataDirectory = queryRunner.getCoordinator().getDataDirectory().resolve(TEST_DATA_DIRECTORY);
Path catalogDirectory = dataDirectory.getParent().resolve(TEST_CATALOG_DIRECTORY);
Path dataDirectory = queryRunner.getCoordinator().getDataDirectory();

queryRunner.installPlugin(new IcebergPlugin());

String catalogType = extraConnectorProperties.getOrDefault("iceberg.catalog.type", HIVE.name());
Map<String, String> icebergProperties = ImmutableMap.<String, String>builder()
.put("iceberg.file-format", format.name())
.put("hive.metastore", "file")
.put("hive.metastore.catalog.dir", catalogDirectory.toFile().toURI().toString())
.putAll(getConnectorProperties(CatalogType.valueOf(catalogType), dataDirectory))
.putAll(extraConnectorProperties)
.build();

Expand All @@ -127,6 +130,22 @@ public static DistributedQueryRunner createIcebergQueryRunner(
return queryRunner;
}

private static Map<String, String> getConnectorProperties(CatalogType icebergCatalogType, Path icebergDataDirectory)
{
Path testDataDirectory = icebergDataDirectory.resolve(TEST_DATA_DIRECTORY);
switch (icebergCatalogType) {
case HADOOP:
case NESSIE:
return ImmutableMap.of("iceberg.catalog.warehouse", testDataDirectory.getParent().toFile().toURI().toString());
case HIVE:
Path testCatalogDirectory = testDataDirectory.getParent().resolve(TEST_CATALOG_DIRECTORY);
return ImmutableMap.of(
"hive.metastore", "file",
"hive.metastore.catalog.dir", testCatalogDirectory.toFile().toURI().toString());
}
throw new PrestoException(NOT_SUPPORTED, "Unsupported Presto Iceberg catalog type " + icebergCatalogType);
}

public static void main(String[] args)
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,10 @@
*/
package com.facebook.presto.iceberg.hadoop;

import com.facebook.presto.Session;
import com.facebook.presto.iceberg.IcebergConfig;
import com.facebook.presto.iceberg.IcebergDistributedTestBase;
import com.facebook.presto.iceberg.IcebergPlugin;
import com.facebook.presto.testing.QueryRunner;
import com.facebook.presto.tests.DistributedQueryRunner;
import com.facebook.presto.tpch.TpchPlugin;
import com.google.common.collect.ImmutableMap;
import io.airlift.tpch.TpchTable;
import org.testng.annotations.Test;

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

import static com.facebook.presto.iceberg.CatalogType.HADOOP;
import static com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tests.QueryAssertions.copyTpchTables;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;

@Test
public class TestIcebergDistributedHadoop
Expand All @@ -42,37 +27,6 @@ public TestIcebergDistributedHadoop()
super(HADOOP);
}

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
Session session = testSessionBuilder()
.setCatalog(ICEBERG_CATALOG)
.setSchema("tpch")
.build();

DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();

queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");

Path dataDirectory = queryRunner.getCoordinator().getDataDirectory().resolve("iceberg_data");

queryRunner.installPlugin(new IcebergPlugin());
Map<String, String> icebergProperties = ImmutableMap.<String, String>builder()
.putAll(ImmutableMap.of("iceberg.catalog.type", HADOOP.name()))
.put("iceberg.file-format", new IcebergConfig().getFileFormat().name())
.put("iceberg.catalog.warehouse", dataDirectory.getParent().toFile().toURI().toString())
.build();

queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties);

queryRunner.execute("CREATE SCHEMA tpch");
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, TpchTable.getTables());

return queryRunner;
}

protected boolean supportsViews()
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,25 @@
*/
package com.facebook.presto.iceberg.hadoop;

import com.facebook.presto.Session;
import com.facebook.presto.hive.s3.HiveS3Config;
import com.facebook.presto.hive.s3.PrestoS3ConfigurationUpdater;
import com.facebook.presto.iceberg.IcebergCatalogName;
import com.facebook.presto.iceberg.IcebergConfig;
import com.facebook.presto.iceberg.IcebergDistributedSmokeTestBase;
import com.facebook.presto.iceberg.IcebergPlugin;
import com.facebook.presto.iceberg.IcebergResourceFactory;
import com.facebook.presto.iceberg.IcebergUtil;
import com.facebook.presto.iceberg.nessie.NessieConfig;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.testing.QueryRunner;
import com.facebook.presto.tests.DistributedQueryRunner;
import com.facebook.presto.tpch.TpchPlugin;
import com.google.common.collect.ImmutableMap;
import io.airlift.tpch.TpchTable;
import org.apache.iceberg.Table;
import org.testng.annotations.Test;

import java.io.File;
import java.nio.file.Path;
import java.util.Map;

import static com.facebook.presto.iceberg.CatalogType.HADOOP;
import static com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tests.QueryAssertions.copyTpchTables;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static java.lang.String.format;

@Test
Expand All @@ -60,37 +50,6 @@ protected String getLocation(String schema, String table)
return format("%s%s/%s", tempLocation.toURI(), schema, table);
}

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
Session session = testSessionBuilder()
.setCatalog(ICEBERG_CATALOG)
.setSchema("tpch")
.build();

DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();

queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");

Path dataDirectory = queryRunner.getCoordinator().getDataDirectory().resolve("iceberg_data");

queryRunner.installPlugin(new IcebergPlugin());
Map<String, String> icebergProperties = ImmutableMap.<String, String>builder()
.putAll(ImmutableMap.of("iceberg.catalog.type", HADOOP.name()))
.put("iceberg.file-format", new IcebergConfig().getFileFormat().name())
.put("iceberg.catalog.warehouse", dataDirectory.getParent().toFile().toURI().toString())
.build();

queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties);

queryRunner.execute("CREATE SCHEMA tpch");
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, TpchTable.getTables());

return queryRunner;
}

@Override
protected Path getCatalogDirectory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,17 @@
*/
package com.facebook.presto.iceberg.nessie;

import com.facebook.presto.Session;
import com.facebook.presto.iceberg.IcebergConfig;
import com.facebook.presto.iceberg.IcebergDistributedTestBase;
import com.facebook.presto.iceberg.IcebergPlugin;
import com.facebook.presto.iceberg.IcebergQueryRunner;
import com.facebook.presto.testing.QueryRunner;
import com.facebook.presto.testing.containers.NessieContainer;
import com.facebook.presto.tests.DistributedQueryRunner;
import com.facebook.presto.tpch.TpchPlugin;
import com.google.common.collect.ImmutableMap;
import io.airlift.tpch.TpchTable;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

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

import static com.facebook.presto.iceberg.CatalogType.NESSIE;
import static com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
import static com.facebook.presto.iceberg.nessie.NessieTestUtil.nessieConnectorProperties;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tests.QueryAssertions.copyTpchTables;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;

@Test
public class TestIcebergDistributedNessie
Expand Down Expand Up @@ -76,30 +64,6 @@ public void tearDown()
protected QueryRunner createQueryRunner()
throws Exception
{
Session session = testSessionBuilder()
.setCatalog(ICEBERG_CATALOG)
.setSchema("tpch")
.build();

DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();

queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");

Path dataDirectory = queryRunner.getCoordinator().getDataDirectory().resolve("iceberg_data");

queryRunner.installPlugin(new IcebergPlugin());
Map<String, String> icebergProperties = ImmutableMap.<String, String>builder()
.putAll(nessieConnectorProperties(nessieContainer.getRestApiUri()))
.put("iceberg.file-format", new IcebergConfig().getFileFormat().name())
.put("iceberg.catalog.warehouse", dataDirectory.getParent().toFile().toURI().toString())
.build();

queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties);

queryRunner.execute("CREATE SCHEMA tpch");
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, TpchTable.getTables());

return queryRunner;
return IcebergQueryRunner.createIcebergQueryRunner(ImmutableMap.of(), nessieConnectorProperties(nessieContainer.getRestApiUri()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,32 @@
*/
package com.facebook.presto.iceberg.nessie;

import com.facebook.presto.Session;
import com.facebook.presto.hive.s3.HiveS3Config;
import com.facebook.presto.hive.s3.PrestoS3ConfigurationUpdater;
import com.facebook.presto.iceberg.IcebergCatalogName;
import com.facebook.presto.iceberg.IcebergConfig;
import com.facebook.presto.iceberg.IcebergDistributedSmokeTestBase;
import com.facebook.presto.iceberg.IcebergPlugin;
import com.facebook.presto.iceberg.IcebergQueryRunner;
import com.facebook.presto.iceberg.IcebergResourceFactory;
import com.facebook.presto.iceberg.IcebergUtil;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.testing.QueryRunner;
import com.facebook.presto.testing.containers.NessieContainer;
import com.facebook.presto.tests.DistributedQueryRunner;
import com.facebook.presto.tpch.TpchPlugin;
import com.google.common.collect.ImmutableMap;
import io.airlift.tpch.TpchTable;
import org.apache.iceberg.Table;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

import static com.facebook.presto.iceberg.CatalogType.NESSIE;
import static com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
import static com.facebook.presto.iceberg.nessie.NessieTestUtil.nessieConnectorProperties;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tests.QueryAssertions.copyTpchTables;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -98,31 +90,7 @@ protected String getLocation(String schema, String table)
protected QueryRunner createQueryRunner()
throws Exception
{
Session session = testSessionBuilder()
.setCatalog(ICEBERG_CATALOG)
.setSchema("tpch")
.build();

DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();

queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");

Path dataDirectory = queryRunner.getCoordinator().getDataDirectory().resolve("iceberg_data");

queryRunner.installPlugin(new IcebergPlugin());
Map<String, String> icebergProperties = ImmutableMap.<String, String>builder()
.putAll(nessieConnectorProperties(nessieContainer.getRestApiUri()))
.put("iceberg.file-format", new IcebergConfig().getFileFormat().name())
.put("iceberg.catalog.warehouse", dataDirectory.getParent().toFile().toURI().toString())
.build();

queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties);

queryRunner.execute("CREATE SCHEMA tpch");
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, TpchTable.getTables());

return queryRunner;
return IcebergQueryRunner.createIcebergQueryRunner(ImmutableMap.of(), nessieConnectorProperties(nessieContainer.getRestApiUri()));
}

@Override
Expand Down
Loading

0 comments on commit d117ff8

Please sign in to comment.