Search in sources :

Example 26 with Session

use of io.prestosql.Session in project hetu-core by openlookeng.

the class AbstractTestQueries method assertDescribeOutputEmpty.

protected void assertDescribeOutputEmpty(@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).build();
    assertEqualsIgnoreOrder(actual, expected);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) Session(io.prestosql.Session)

Example 27 with Session

use of io.prestosql.Session in project hetu-core by openlookeng.

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(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 28 with Session

use of io.prestosql.Session in project hetu-core by openlookeng.

the class AbstractTestQueries method testDescribeOutputOnAliasedColumnsAndExpressions.

@Test
public void testDescribeOutputOnAliasedColumnsAndExpressions() {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SELECT count(*) AS this_is_aliased, 1 + 2 FROM nation").build();
    MaterializedResult actual = computeActual(session, "DESCRIBE OUTPUT my_query");
    MaterializedResult expected = resultBuilder(session, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BOOLEAN).row("this_is_aliased", "", "", "", "bigint", 8, true).row("_col1", "", "", "", "integer", 4, false).build();
    assertEqualsIgnoreOrder(actual, expected);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 29 with Session

use of io.prestosql.Session in project hetu-core by openlookeng.

the class AbstractTestStarTreeQueries method testOtherQueryTypes.

@Test
public void testOtherQueryTypes() {
    List<Session> sessions = ImmutableList.of(Session.builder(getSession()).setSystemProperty(SystemSessionProperties.ENABLE_STAR_TREE_INDEX, "true").setSystemProperty(SystemSessionProperties.ENABLE_EXECUTION_PLAN_CACHE, "true").build(), Session.builder(getSession()).setSystemProperty(SystemSessionProperties.ENABLE_STAR_TREE_INDEX, "false").setSystemProperty(SystemSessionProperties.ENABLE_EXECUTION_PLAN_CACHE, "true").build(), Session.builder(getSession()).setSystemProperty(SystemSessionProperties.ENABLE_STAR_TREE_INDEX, "true").setSystemProperty(SystemSessionProperties.ENABLE_EXECUTION_PLAN_CACHE, "false").build(), Session.builder(getSession()).setSystemProperty(SystemSessionProperties.ENABLE_STAR_TREE_INDEX, "false").setSystemProperty(SystemSessionProperties.ENABLE_EXECUTION_PLAN_CACHE, "false").build());
    for (Session session : sessions) {
        assertQuery(session, "WITH temp_table as(SELECT nationkey, count(*) AS count FROM nation WHERE nationkey > 10 GROUP BY nationkey) SELECT nationkey, count FROM temp_table");
        assertQuery(session, "SELECT o.orderpriority, COUNT(*) FROM orders o WHERE o.orderdate >= date '1993-07-01' AND EXISTS (SELECT * FROM lineitem l WHERE l.orderkey = o.orderkey AND (l.returnflag = 'R' OR l.receiptdate > l.commitdate)) GROUP BY o.orderpriority");
        assertQuerySucceeds(session, "create view count_by_shipmode_cube_test_1 as select shipmode, count(*) as count from lineitem group by shipmode");
        assertQuerySucceeds(session, "DROP VIEW count_by_shipmode_cube_test_1");
        assertQuerySucceeds(session, "select sum(l.extendedprice) / 7.0 as avg_yearly from lineitem l, part p where p.partkey = l.partkey and p.brand = 'Brand#33' and p.container = 'WRAP PACK' and l.quantity < (select 0.2 * avg(l2.quantity) from lineitem l2 where l2.partkey = p.partkey)");
    }
}
Also used : Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 30 with Session

use of io.prestosql.Session in project hetu-core by openlookeng.

the class AbstractTestQueries method testShowSession.

@Test
public void testShowSession() {
    Session session = new Session(getSession().getQueryId(), Optional.empty(), getSession().isClientTransactionSupport(), getSession().getIdentity(), getSession().getSource(), getSession().getCatalog(), getSession().getSchema(), getSession().getPath(), getSession().getTraceToken(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(), getSession().getUserAgent(), getSession().getClientInfo(), getSession().getClientTags(), getSession().getClientCapabilities(), getSession().getResourceEstimates(), getSession().getStartTime(), ImmutableMap.<String, String>builder().put("test_string", "foo string").put("test_long", "424242").build(), ImmutableMap.of(), ImmutableMap.of(TESTING_CATALOG, ImmutableMap.<String, String>builder().put("connector_string", "bar string").put("connector_long", "11").build()), getQueryRunner().getMetadata().getSessionPropertyManager(), getSession().getPreparedStatements(), getSession().isPageMetadataEnabled());
    MaterializedResult result = computeActual(session, "SHOW SESSION");
    ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> {
        assertEquals(input.getFieldCount(), 5);
        return (String) input.getField(0);
    });
    assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property"));
    assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property"));
    assertEquals(properties.get(TESTING_CATALOG + ".connector_string"), new MaterializedRow(1, TESTING_CATALOG + ".connector_string", "bar string", "connector default", "varchar", "connector string property"));
    assertEquals(properties.get(TESTING_CATALOG + ".connector_long"), new MaterializedRow(1, TESTING_CATALOG + ".connector_long", "11", "33", "bigint", "connector long property"));
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Aggregations

Session (io.prestosql.Session)254 Test (org.testng.annotations.Test)131 List (java.util.List)52 Optional (java.util.Optional)50 Map (java.util.Map)43 Metadata (io.prestosql.metadata.Metadata)41 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)41 MaterializedResult (io.prestosql.testing.MaterializedResult)40 Objects.requireNonNull (java.util.Objects.requireNonNull)39 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)35 PrestoException (io.prestosql.spi.PrestoException)31 TableHandle (io.prestosql.spi.metadata.TableHandle)31 Set (java.util.Set)31 ImmutableList (com.google.common.collect.ImmutableList)29 Type (io.prestosql.spi.type.Type)29 HashMap (java.util.HashMap)29 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)27 Symbol (io.prestosql.spi.plan.Symbol)27 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)26 ImmutableSet (com.google.common.collect.ImmutableSet)26