Search in sources :

Example 36 with QueryId

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

the class TestRollbackTask method testUnknownTransactionRollback.

@Test
public void testUnknownTransactionRollback() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
    TransactionId.create()).build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    // Still issue clear signal
    assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) Rollback(com.facebook.presto.sql.tree.Rollback) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 37 with QueryId

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

the class TestSetSessionTask method testSetSessionWithParameters.

private void testSetSessionWithParameters(Expression expression, String expectedValue, List<Expression> parameters) throws Exception {
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "set foo.bar = 'baz'", TEST_SESSION, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    getFutureValue(new SetSessionTask().execute(new SetSession(QualifiedName.of(CATALOG_NAME, "bar"), expression), transactionManager, metadata, accessControl, stateMachine, parameters));
    Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
    assertEquals(sessionProperties, ImmutableMap.of("foo.bar", expectedValue));
}
Also used : SetSession(com.facebook.presto.sql.tree.SetSession) QueryId(com.facebook.presto.spi.QueryId)

Example 38 with QueryId

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

the class TestPrepareTask method executePrepare.

private Map<String, String> executePrepare(String statementName, Statement statement, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), sqlString, session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    Prepare prepare = new Prepare(statementName, statement);
    new PrepareTask(new SqlParser()).execute(prepare, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList());
    return stateMachine.getAddedPreparedStatements();
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SqlParser(com.facebook.presto.sql.parser.SqlParser) Prepare(com.facebook.presto.sql.tree.Prepare) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl)

Example 39 with QueryId

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

the class TestBasicQueryInfo method testConstructor.

@Test
public void testConstructor() {
    BasicQueryInfo basicInfo = new BasicQueryInfo(new QueryInfo(new QueryId("0"), TEST_SESSION.toSessionRepresentation(), RUNNING, new MemoryPoolId("reserved"), false, URI.create("1"), ImmutableList.of("2", "3"), "SELECT 4", new QueryStats(DateTime.parse("1991-09-06T05:00-05:30"), DateTime.parse("1991-09-06T05:01-05:30"), DateTime.parse("1991-09-06T05:02-05:30"), DateTime.parse("1991-09-06T06:00-05:30"), Duration.valueOf("8m"), Duration.valueOf("7m"), Duration.valueOf("9m"), Duration.valueOf("10m"), Duration.valueOf("11m"), Duration.valueOf("12m"), 13, 14, 15, 16, 17, 18, 19, 20.0, DataSize.valueOf("21GB"), DataSize.valueOf("22GB"), Duration.valueOf("23m"), Duration.valueOf("24m"), Duration.valueOf("25m"), Duration.valueOf("26m"), true, ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY), DataSize.valueOf("27GB"), 28, DataSize.valueOf("29GB"), 30, DataSize.valueOf("31GB"), 32, ImmutableList.of()), ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), false, "33", Optional.empty(), null, StandardErrorCode.ABANDONED_QUERY.toErrorCode(), ImmutableSet.of(), Optional.empty(), false, Optional.empty()));
    assertEquals(basicInfo.getQueryId().getId(), "0");
    assertEquals(basicInfo.getState(), RUNNING);
    assertEquals(basicInfo.getMemoryPool().getId(), "reserved");
    assertEquals(basicInfo.isScheduled(), false);
    assertEquals(basicInfo.getQuery(), "SELECT 4");
    assertEquals(basicInfo.getQueryStats().getCreateTime(), DateTime.parse("1991-09-06T05:00-05:30"));
    assertEquals(basicInfo.getQueryStats().getEndTime(), DateTime.parse("1991-09-06T06:00-05:30"));
    assertEquals(basicInfo.getQueryStats().getElapsedTime(), Duration.valueOf("8m"));
    assertEquals(basicInfo.getQueryStats().getExecutionTime(), Duration.valueOf("1m"));
    assertEquals(basicInfo.getQueryStats().getTotalDrivers(), 16);
    assertEquals(basicInfo.getQueryStats().getQueuedDrivers(), 17);
    assertEquals(basicInfo.getQueryStats().getRunningDrivers(), 18);
    assertEquals(basicInfo.getQueryStats().getCompletedDrivers(), 19);
    assertEquals(basicInfo.getQueryStats().getCumulativeMemory(), 20.0);
    assertEquals(basicInfo.getQueryStats().getTotalMemoryReservation(), DataSize.valueOf("21GB"));
    assertEquals(basicInfo.getQueryStats().getPeakMemoryReservation(), DataSize.valueOf("22GB"));
    assertEquals(basicInfo.getQueryStats().getTotalCpuTime(), Duration.valueOf("24m"));
    assertEquals(basicInfo.getQueryStats().isFullyBlocked(), true);
    assertEquals(basicInfo.getQueryStats().getBlockedReasons(), ImmutableSet.of(BlockedReason.WAITING_FOR_MEMORY));
    assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode());
    assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());
}
Also used : QueryStats(com.facebook.presto.execution.QueryStats) QueryId(com.facebook.presto.spi.QueryId) QueryInfo(com.facebook.presto.execution.QueryInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Test(org.testng.annotations.Test)

Example 40 with QueryId

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

the class TestingTaskContext method createTaskContext.

public static TaskContext createTaskContext(Executor executor, Session session, DataSize maxMemory) {
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(1, GIGABYTE));
    MemoryPool systemMemoryPool = new MemoryPool(new MemoryPoolId("testSystem"), new DataSize(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test_query"), maxMemory, memoryPool, systemMemoryPool, executor);
    return createTaskContext(queryContext, executor, session);
}
Also used : DataSize(io.airlift.units.DataSize) QueryId(com.facebook.presto.spi.QueryId) QueryContext(com.facebook.presto.memory.QueryContext) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)42 Test (org.testng.annotations.Test)26 Session (com.facebook.presto.Session)20 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)17 AccessControl (com.facebook.presto.security.AccessControl)15 AccessControlManager (com.facebook.presto.security.AccessControlManager)15 TransactionManager (com.facebook.presto.transaction.TransactionManager)15 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)15 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)10 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 PrestoException (com.facebook.presto.spi.PrestoException)6 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 DataSize (io.airlift.units.DataSize)5 QueryInfo (com.facebook.presto.execution.QueryInfo)4 MemoryPool (com.facebook.presto.memory.MemoryPool)4 QueryContext (com.facebook.presto.memory.QueryContext)4 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)4 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)4