Search in sources :

Example 46 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestResetSessionTask method test.

@Test
public void test() throws Exception {
    Session session = testSessionBuilder(metadata.getSessionPropertyManager()).setSystemProperty("foo", "bar").setCatalogSessionProperty(CATALOG_NAME, "baz", "blah").build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "reset foo", session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    getFutureValue(new ResetSessionTask().execute(new ResetSession(QualifiedName.of(CATALOG_NAME, "baz")), transactionManager, metadata, accessControl, stateMachine, emptyList()));
    Set<String> sessionProperties = stateMachine.getResetSessionProperties();
    assertEquals(sessionProperties, ImmutableSet.of("catalog.baz"));
}
Also used : QueryId(com.facebook.presto.spi.QueryId) ResetSession(com.facebook.presto.sql.tree.ResetSession) ResetSession(com.facebook.presto.sql.tree.ResetSession) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 47 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestRollbackTask method testRollback.

@Test
public void testRollback() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    assertTrue(stateMachine.getSession().getTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    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 48 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestRollbackTask method testNoTransactionRollback.

@Test
public void testNoTransactionRollback() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    Session session = sessionBuilder().build();
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
    try {
        try {
            getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
            fail();
        } catch (CompletionException e) {
            throw Throwables.propagate(e.getCause());
        }
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_IN_TRANSACTION.toErrorCode());
    }
    assertFalse(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) CompletionException(java.util.concurrent.CompletionException) PrestoException(com.facebook.presto.spi.PrestoException) 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 49 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestPrepareTask method testPrepareNameExists.

@Test
public void testPrepareNameExists() {
    Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT bar, baz from foo").build();
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
    String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
    Map<String, String> statements = executePrepare("my_query", query, sqlString, session);
    assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n  foo\n"));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) AllColumns(com.facebook.presto.sql.tree.AllColumns) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 50 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestQueryQueueDefinition method testNameExpansion.

@Test
public void testNameExpansion() {
    Session session = TestingSession.testSessionBuilder().setIdentity(new Identity("bob", Optional.empty())).setSource("the-internet").build();
    QueryQueueDefinition definition = new QueryQueueDefinition("user.${USER}", 1, 1);
    assertEquals(definition.getExpandedTemplate(session), "user.bob");
    definition = new QueryQueueDefinition("source.${SOURCE}", 1, 1);
    assertEquals(definition.getExpandedTemplate(session), "source.the-internet");
    definition = new QueryQueueDefinition("${USER}.${SOURCE}", 1, 1);
    assertEquals(definition.getExpandedTemplate(session), "bob.the-internet");
    definition = new QueryQueueDefinition("global", 1, 1);
    assertEquals(definition.getExpandedTemplate(session), "global");
}
Also used : Identity(com.facebook.presto.spi.security.Identity) Session(com.facebook.presto.Session) TestingSession(com.facebook.presto.testing.TestingSession) Test(org.testng.annotations.Test)

Aggregations

Session (com.facebook.presto.Session)121 Test (org.testng.annotations.Test)61 QueryId (com.facebook.presto.spi.QueryId)21 MaterializedResult (com.facebook.presto.testing.MaterializedResult)20 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)19 PrestoException (com.facebook.presto.spi.PrestoException)17 TransactionManager (com.facebook.presto.transaction.TransactionManager)16 AccessControl (com.facebook.presto.security.AccessControl)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)14 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)14 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)13 AccessControlManager (com.facebook.presto.security.AccessControlManager)13 ConnectorId (com.facebook.presto.connector.ConnectorId)12 LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)12 Type (com.facebook.presto.spi.type.Type)11 List (java.util.List)11 TableHandle (com.facebook.presto.metadata.TableHandle)10 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)10 Optional (java.util.Optional)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9