Search in sources :

Example 16 with Session

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

the class AbstractTestQueries method testExplainSetSessionWithUsing.

@Test
public void testExplainSetSessionWithUsing() {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SET SESSION foo = ?").build();
    MaterializedResult result = computeActual(session, "EXPLAIN (TYPE LOGICAL) EXECUTE my_query USING 7");
    assertEquals(getOnlyElement(result.getOnlyColumnAsSet()), "SET SESSION foo = 7");
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 17 with Session

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

the class AbstractTestQueries method testDescribeInputNoParameters.

@Test
public void testDescribeInputNoParameters() {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", "select * from nation").build();
    MaterializedResult actual = computeActual(session, "DESCRIBE INPUT my_query");
    MaterializedResult expected = resultBuilder(session, BIGINT, VARCHAR).build();
    assertEquals(actual, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 18 with Session

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

the class AbstractTestQueries method testExecuteWithParametersInGroupBy.

@Test
public void testExecuteWithParametersInGroupBy() {
    try {
        String query = "SELECT a + ?, count(1) FROM (VALUES 1, 2, 3, 2) t(a) GROUP BY a + ?";
        Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
        computeActual(session, "EXECUTE my_query USING 1, 1");
        fail("parameters in group by and select should fail");
    } catch (SemanticException e) {
        assertEquals(e.getCode(), MUST_BE_AGGREGATE_OR_GROUP_BY);
    } catch (RuntimeException e) {
        assertEquals(e.getMessage(), "line 1:10: '(\"a\" + ?)' must be an aggregate expression or appear in GROUP BY clause");
    }
}
Also used : Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 19 with Session

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

the class AbstractTestQueries method assertDescribeOutputRowCount.

private void assertDescribeOutputRowCount(@Language("SQL") String sql) {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", sql).build();
    MaterializedResult actual = computeActual(session, "DESCRIBE OUTPUT my_query");
    MaterializedResult expected = resultBuilder(session, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN).row("rows", "", "", "", "bigint", 8, false).build();
    assertEqualsIgnoreOrder(actual, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session)

Example 20 with Session

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

the class TestMemoryManager method testResourceOverCommit.

@Test(timeOut = 240_000)
public void testResourceOverCommit() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("query.max-memory-per-node", "1kB").put("query.max-memory", "1kB").build();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        try {
            queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
            fail();
        } catch (RuntimeException e) {
        // expected
        }
        Session session = testSessionBuilder().setCatalog("tpch").setSchema("tiny").setSystemProperty(RESOURCE_OVERCOMMIT, "true").build();
        queryRunner.execute(session, "SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) 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