Search in sources :

Example 1 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestHttpRequestSessionFactory method testInvalidTimeZone.

@Test(expectedExceptions = PrestoException.class)
public void testInvalidTimeZone() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_TIME_ZONE, "unknown_timezone").build(), "testRemote");
    HttpRequestSessionFactory sessionFactory = new HttpRequestSessionFactory(request);
    sessionFactory.createSession(new QueryId("test_query_id"), createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) Test(org.testng.annotations.Test)

Example 2 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestHttpRequestSessionFactory method testCreateSession.

@Test
public void testCreateSession() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest(ImmutableListMultimap.<String, String>builder().put(PRESTO_USER, "testUser").put(PRESTO_SOURCE, "testSource").put(PRESTO_CATALOG, "testCatalog").put(PRESTO_SCHEMA, "testSchema").put(PRESTO_LANGUAGE, "zh-TW").put(PRESTO_TIME_ZONE, "Asia/Taipei").put(PRESTO_CLIENT_INFO, "client-info").put(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB").put(PRESTO_SESSION, DISTRIBUTED_JOIN + "=true," + HASH_PARTITION_COUNT + " = 43").put(PRESTO_PREPARED_STATEMENT, "query1=select * from foo,query2=select * from bar").build(), "testRemote");
    HttpRequestSessionFactory sessionFactory = new HttpRequestSessionFactory(request);
    Session session = sessionFactory.createSession(new QueryId("test_query_id"), createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager());
    assertEquals(session.getQueryId(), new QueryId("test_query_id"));
    assertEquals(session.getUser(), "testUser");
    assertEquals(session.getSource().get(), "testSource");
    assertEquals(session.getCatalog().get(), "testCatalog");
    assertEquals(session.getSchema().get(), "testSchema");
    assertEquals(session.getLocale(), Locale.TAIWAN);
    assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
    assertEquals(session.getRemoteUserAddress().get(), "testRemote");
    assertEquals(session.getClientInfo().get(), "client-info");
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(DISTRIBUTED_JOIN, "true").put(HASH_PARTITION_COUNT, "43").build());
    assertEquals(session.getPreparedStatements(), ImmutableMap.<String, String>builder().put("query1", "select * from foo").put("query2", "select * from bar").build());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with QueryId

use of com.facebook.presto.spi.QueryId 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 4 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class InformationSchemaPageSourceProvider method getInternalTable.

private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) {
    InformationSchemaTransactionHandle transaction = (InformationSchemaTransactionHandle) transactionHandle;
    InformationSchemaSplit split = (InformationSchemaSplit) connectorSplit;
    requireNonNull(columns, "columns is null");
    InformationSchemaTableHandle handle = split.getTableHandle();
    Map<String, NullableValue> filters = split.getFilters();
    Session session = Session.builder(metadata.getSessionPropertyManager()).setTransactionId(transaction.getTransactionId()).setQueryId(new QueryId(connectorSession.getQueryId())).setIdentity(connectorSession.getIdentity()).setSource("information_schema").setCatalog(// default catalog is not be used
    "").setSchema(// default schema is not be used
    "").setTimeZoneKey(connectorSession.getTimeZoneKey()).setLocale(connectorSession.getLocale()).setStartTime(connectorSession.getStartTime()).build();
    return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters);
}
Also used : QueryId(com.facebook.presto.spi.QueryId) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Session(com.facebook.presto.Session)

Example 5 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestQueues method testBasic.

private void testBasic(boolean resourceGroups) throws Exception {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    if (resourceGroups) {
        builder.put("experimental.resource-groups-enabled", "true");
    } else {
        builder.put("query.queue-config-file", getResourceFilePath("queue_config_dashboard.json"));
    }
    Map<String, String> properties = builder.build();
    try (DistributedQueryRunner queryRunner = createQueryRunner(properties)) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        // submit first "dashboard" query
        QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        // wait for the first "dashboard" query to start
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        // submit second "dashboard" query
        QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        // wait for the second "dashboard" query to be queued ("dashboard.${USER}" queue strategy only allows one "dashboard" query to be accepted for execution)
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        // submit first non "dashboard" query
        QueryId firstNonDashboardQuery = createQuery(queryRunner, newSession(), LONG_LASTING_QUERY);
        // wait for the first non "dashboard" query to start
        waitForQueryState(queryRunner, firstNonDashboardQuery, RUNNING);
        // submit second non "dashboard" query
        QueryId secondNonDashboardQuery = createQuery(queryRunner, newSession(), LONG_LASTING_QUERY);
        // wait for the second non "dashboard" query to start
        waitForQueryState(queryRunner, secondNonDashboardQuery, RUNNING);
        // cancel first "dashboard" query, second "dashboard" query and second non "dashboard" query should start running
        cancelQuery(queryRunner, firstDashboardQuery);
        waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
        waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) QueryId(com.facebook.presto.spi.QueryId) ResourceGroupManagerPlugin(com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)121 Test (org.testng.annotations.Test)79 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)19 DataSize (io.airlift.units.DataSize)18 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)17 Session (com.facebook.presto.Session)16 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)16 QueryManager (com.facebook.presto.execution.QueryManager)15 Identity (com.facebook.presto.spi.security.Identity)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ArrayList (java.util.ArrayList)11 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)10 PrestoException (com.facebook.presto.spi.PrestoException)10 ConnectorIdentity (com.facebook.presto.spi.security.ConnectorIdentity)10 List (java.util.List)10 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)9 MemoryPool (com.facebook.presto.memory.MemoryPool)9 ImmutableList (com.google.common.collect.ImmutableList)9 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)8 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)7