Search in sources :

Example 6 with LocalQueryRunner

use of com.facebook.presto.testing.LocalQueryRunner in project presto by prestodb.

the class TestLocalQueries method createLocalQueryRunner.

public static LocalQueryRunner createLocalQueryRunner() {
    Session defaultSession = testSessionBuilder().setCatalog("local").setSchema(TINY_SCHEMA_NAME).setSystemProperty(REORDER_JOINS, "true").build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
    // add the tpch catalog
    // local queries run directly against the generator
    localQueryRunner.createCatalog(defaultSession.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    localQueryRunner.getMetadata().addFunctions(CUSTOM_FUNCTIONS);
    SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager();
    sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES);
    sessionPropertyManager.addConnectorSessionProperties(new ConnectorId(TESTING_CATALOG), TEST_CATALOG_PROPERTIES);
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 7 with LocalQueryRunner

use of com.facebook.presto.testing.LocalQueryRunner in project presto by prestodb.

the class TestMemoryPools method testBlocking.

@Test
public void testBlocking() throws Exception {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("tiny").setSystemProperty("task_default_concurrency", "1").build();
    LocalQueryRunner localQueryRunner = queryRunnerWithInitialTransaction(session);
    // add tpch
    localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
    // reserve all the memory in the pool
    MemoryPool pool = new MemoryPool(new MemoryPoolId("test"), new DataSize(10, MEGABYTE));
    QueryId fakeQueryId = new QueryId("fake");
    assertTrue(pool.tryReserve(fakeQueryId, TEN_MEGABYTES));
    MemoryPool systemPool = new MemoryPool(new MemoryPoolId("testSystem"), new DataSize(10, MEGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("query"), new DataSize(10, MEGABYTE), pool, systemPool, localQueryRunner.getExecutor());
    // discard all output
    OutputFactory outputFactory = new PageConsumerOutputFactory(types -> (page -> {
    }));
    TaskContext taskContext = createTaskContext(queryContext, localQueryRunner.getExecutor(), session);
    List<Driver> drivers = localQueryRunner.createDrivers("SELECT COUNT(*) FROM orders JOIN lineitem USING (orderkey)", outputFactory, taskContext);
    // run driver, until it blocks
    while (!isWaitingForMemory(drivers)) {
        for (Driver driver : drivers) {
            driver.process();
        }
    }
    // driver should be blocked waiting for memory
    for (Driver driver : drivers) {
        assertFalse(driver.isFinished());
    }
    assertTrue(pool.getFreeBytes() <= 0);
    pool.free(fakeQueryId, TEN_MEGABYTES);
    do {
        assertFalse(isWaitingForMemory(drivers));
        boolean progress = false;
        for (Driver driver : drivers) {
            ListenableFuture<?> blocked = driver.process();
            progress = progress | blocked.isDone();
        }
        // query should not block
        assertTrue(progress);
    } while (!drivers.stream().allMatch(Driver::isFinished));
}
Also used : LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) PageConsumerOutputFactory(com.facebook.presto.testing.PageConsumerOperator.PageConsumerOutputFactory) TaskContext(com.facebook.presto.operator.TaskContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) OutputFactory(com.facebook.presto.operator.OutputFactory) Test(org.testng.annotations.Test) Driver(com.facebook.presto.operator.Driver) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) DataSize(io.airlift.units.DataSize) List(java.util.List) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) LocalQueryRunner.queryRunnerWithInitialTransaction(com.facebook.presto.testing.LocalQueryRunner.queryRunnerWithInitialTransaction) OperatorContext(com.facebook.presto.operator.OperatorContext) Assert.assertFalse(org.testng.Assert.assertFalse) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TaskContext(com.facebook.presto.operator.TaskContext) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) PageConsumerOutputFactory(com.facebook.presto.testing.PageConsumerOperator.PageConsumerOutputFactory) QueryId(com.facebook.presto.spi.QueryId) Driver(com.facebook.presto.operator.Driver) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) DataSize(io.airlift.units.DataSize) PageConsumerOutputFactory(com.facebook.presto.testing.PageConsumerOperator.PageConsumerOutputFactory) OutputFactory(com.facebook.presto.operator.OutputFactory) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 8 with LocalQueryRunner

use of com.facebook.presto.testing.LocalQueryRunner in project presto by prestodb.

the class HiveBenchmarkQueryRunner method createLocalQueryRunner.

public static LocalQueryRunner createLocalQueryRunner(File tempDir) {
    Session session = testSessionBuilder().setCatalog("hive").setSchema("tpch").build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(session);
    // add tpch
    localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
    // add hive
    File hiveDir = new File(tempDir, "hive_data");
    TestingHiveMetastore metastore = new TestingHiveMetastore(hiveDir);
    metastore.createDatabase(Database.builder().setDatabaseName("tpch").setOwnerName("public").setOwnerType(PrincipalType.ROLE).build());
    HiveConnectorFactory hiveConnectorFactory = new HiveConnectorFactory("hive", HiveBenchmarkQueryRunner.class.getClassLoader(), metastore);
    Map<String, String> hiveCatalogConfig = ImmutableMap.<String, String>builder().put("hive.metastore.uri", "thrift://none.invalid:0").put("hive.max-split-size", "10GB").build();
    localQueryRunner.createCatalog("hive", hiveConnectorFactory, hiveCatalogConfig);
    localQueryRunner.execute("CREATE TABLE orders AS SELECT * FROM tpch.sf1.orders");
    localQueryRunner.execute("CREATE TABLE lineitem AS SELECT * FROM tpch.sf1.lineitem");
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingHiveMetastore(com.facebook.presto.hive.metastore.TestingHiveMetastore) File(java.io.File) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session)

Example 9 with LocalQueryRunner

use of com.facebook.presto.testing.LocalQueryRunner in project presto by prestodb.

the class HiveBenchmarkQueryRunner method main.

public static void main(String[] args) throws IOException {
    String outputDirectory = requireNonNull(System.getProperty("outputDirectory"), "Must specify -DoutputDirectory=...");
    File tempDir = Files.createTempDir();
    try (LocalQueryRunner localQueryRunner = createLocalQueryRunner(tempDir)) {
        new BenchmarkSuite(localQueryRunner, outputDirectory).runAllBenchmarks();
    } finally {
        FileUtils.deleteRecursively(tempDir);
    }
}
Also used : File(java.io.File) BenchmarkSuite(com.facebook.presto.benchmark.BenchmarkSuite) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner)

Example 10 with LocalQueryRunner

use of com.facebook.presto.testing.LocalQueryRunner in project presto by prestodb.

the class TestMLQueries method createLocalQueryRunner.

private static LocalQueryRunner createLocalQueryRunner() {
    Session defaultSession = testSessionBuilder().setCatalog("local").setSchema(TINY_SCHEMA_NAME).build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
    // add the tpch catalog
    // local queries run directly against the generator
    localQueryRunner.createCatalog(defaultSession.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    MLPlugin plugin = new MLPlugin();
    for (Type type : plugin.getTypes()) {
        localQueryRunner.getTypeManager().addType(type);
    }
    for (ParametricType parametricType : plugin.getParametricTypes()) {
        localQueryRunner.getTypeManager().addParametricType(parametricType);
    }
    localQueryRunner.getMetadata().addFunctions(extractFunctions(new MLPlugin().getFunctions()));
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) Type(com.facebook.presto.spi.type.Type) ParametricType(com.facebook.presto.spi.type.ParametricType) ParametricType(com.facebook.presto.spi.type.ParametricType) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session)

Aggregations

LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)19 Session (com.facebook.presto.Session)13 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)11 ConnectorId (com.facebook.presto.connector.ConnectorId)3 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)3 Plan (com.facebook.presto.sql.planner.Plan)3 BenchmarkQueryRunner.createLocalQueryRunner (com.facebook.presto.benchmark.BenchmarkQueryRunner.createLocalQueryRunner)2 TestingSession.testSessionBuilder (com.facebook.presto.testing.TestingSession.testSessionBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 SessionBuilder (com.facebook.presto.Session.SessionBuilder)1 BenchmarkSuite (com.facebook.presto.benchmark.BenchmarkSuite)1 TestingHiveMetastore (com.facebook.presto.hive.metastore.TestingHiveMetastore)1 Driver (com.facebook.presto.operator.Driver)1 OperatorContext (com.facebook.presto.operator.OperatorContext)1 OutputFactory (com.facebook.presto.operator.OutputFactory)1 TaskContext (com.facebook.presto.operator.TaskContext)1 MemoryConnectorFactory (com.facebook.presto.plugin.memory.MemoryConnectorFactory)1 QueryId (com.facebook.presto.spi.QueryId)1 ConnectorFactory (com.facebook.presto.spi.connector.ConnectorFactory)1