Search in sources :

Example 1 with Session

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

the class LocalAtopQueryRunner method createQueryRunner.

public static LocalQueryRunner createQueryRunner(Map<String, String> catalogProperties, Class<? extends AtopFactory> factoryClass) throws Exception {
    Session session = testSessionBuilder().setCatalog("atop").setSchema("default").setTimeZoneKey(TimeZoneKey.getTimeZoneKey(TimeZone.getDefault().getID())).build();
    LocalQueryRunner queryRunner = new LocalQueryRunner(session);
    try {
        AtopConnectorFactory connectorFactory = new AtopConnectorFactory(factoryClass, LocalAtopQueryRunner.class.getClassLoader());
        ImmutableMap.Builder<String, String> properties = ImmutableMap.<String, String>builder().putAll(catalogProperties).put("atop.max-history-days", "1");
        queryRunner.createCatalog("atop", connectorFactory, properties.build());
        return queryRunner;
    } catch (Exception e) {
        closeAllSuppress(e, queryRunner);
        throw e;
    }
}
Also used : LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session)

Example 2 with Session

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

the class TestAtopSecurity method testAdminCanRead.

@Test
public void testAdminCanRead() {
    Session admin = getSession("admin");
    queryRunner.execute(admin, "SELECT * FROM disks");
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with Session

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

the class TestAtopSecurity method testNonAdminCannotRead.

@Test(expectedExceptions = AccessDeniedException.class)
public void testNonAdminCannotRead() {
    Session bob = getSession("bob");
    queryRunner.execute(bob, "SELECT * FROM disks");
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 4 with Session

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

the class MemoryLocalQueryRunner method execute.

public void execute(@Language("SQL") String query) {
    Session session = testSessionBuilder().setSystemProperty("optimizer.optimize-hash-generation", "true").build();
    ExecutorService executor = localQueryRunner.getExecutor();
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(1, GIGABYTE));
    MemoryPool systemMemoryPool = new MemoryPool(new MemoryPoolId("testSystem"), new DataSize(1, GIGABYTE));
    TaskContext taskContext = new QueryContext(new QueryId("test"), new DataSize(256, MEGABYTE), memoryPool, systemMemoryPool, executor).addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0), executor), session, false, false);
    // Use NullOutputFactory to avoid coping out results to avoid affecting benchmark results
    List<Driver> drivers = localQueryRunner.createDrivers(query, new NullOutputOperator.NullOutputFactory(), taskContext);
    boolean done = false;
    while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
            if (!driver.isFinished()) {
                driver.process();
                processed = true;
            }
        }
        done = !processed;
    }
}
Also used : TaskContext(com.facebook.presto.operator.TaskContext) TaskId(com.facebook.presto.execution.TaskId) QueryId(com.facebook.presto.spi.QueryId) Driver(com.facebook.presto.operator.Driver) QueryContext(com.facebook.presto.memory.QueryContext) NullOutputOperator(com.facebook.presto.testing.NullOutputOperator) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) DataSize(io.airlift.units.DataSize) ExecutorService(java.util.concurrent.ExecutorService) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Session(com.facebook.presto.Session) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 5 with Session

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

the class TestBlackHoleSmoke method notAllPropertiesSetForDataGeneration.

@Test
public void notAllPropertiesSetForDataGeneration() {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    try {
        assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 3, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session);
        fail("Expected exception to be thrown here!");
    } catch (RuntimeException ex) {
    // expected exception
    }
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

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