Search in sources :

Example 51 with Session

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

the class AbstractTestQueries method testDescribeOutputShowTables.

@Test
public void testDescribeOutputShowTables() {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SHOW TABLES").build();
    MaterializedResult actual = computeActual(session, "DESCRIBE OUTPUT my_query");
    MaterializedResult expected = resultBuilder(session, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN).row("Table", session.getCatalog().get(), "information_schema", "tables", "varchar", 0, true).build();
    assertEqualsIgnoreOrder(actual, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 52 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 53 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 54 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 55 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)

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