Search in sources :

Example 21 with Session

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

the class AbstractTestDistributedQueries method testComplexCast.

@Test
public void testComplexCast() {
    Session session = Session.builder(getSession()).setSystemProperty(SystemSessionProperties.OPTIMIZE_DISTINCT_AGGREGATIONS, "true").build();
    // This is optimized using CAST(null AS interval day to second) which may be problematic to deserialize on worker
    assertQuery(session, "WITH t(a, b) AS (VALUES (1, INTERVAL '1' SECOND)) " + "SELECT count(DISTINCT a), CAST(max(b) AS VARCHAR) FROM t", "VALUES (1, '0 00:00:01.000')");
}
Also used : TestingSession(io.prestosql.testing.TestingSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 22 with Session

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

the class AbstractTestDistributedQueries method testPushdownCacheFilterKey.

@Test
public void testPushdownCacheFilterKey() {
    if (supportsPushdown()) {
        assertUpdate("DROP TABLE IF EXISTS test_cache_predicate");
        assertUpdate("CREATE TABLE test_cache_predicate (id int, name varchar, p1 int) WITH (partitioned_by=ARRAY['p1'])");
        assertTrue(getQueryRunner().tableExists(getSession(), "test_cache_predicate"));
        assertTableColumnNames("test_cache_predicate", "id", "name", "p1");
        assertUpdate("INSERT INTO test_cache_predicate VALUES (1,'---',1), (2,'---',1), (3,'abc',1)", 3);
        Session sessionPushdown = Session.builder(getSession()).setCatalogSessionProperty(getSession().getCatalog().get(), "orc_predicate_pushdown_enabled", "true").setCatalogSessionProperty(getSession().getCatalog().get(), "orc_row_data_cache_enabled", "false").build();
        Session sessionCachePushdown = Session.builder(getSession()).setCatalogSessionProperty(getSession().getCatalog().get(), "orc_predicate_pushdown_enabled", "true").setCatalogSessionProperty(getSession().getCatalog().get(), "orc_row_data_cache_enabled", "true").build();
        MaterializedResult resultNormal;
        MaterializedResult resultPushdown;
        MaterializedResult resultCachePushdown;
        String sql = "SELECT * FROM test_cache_predicate WHERE id=3 AND name='abc'";
        resultNormal = computeActual(sql);
        resultPushdown = computeActual(sessionPushdown, sql);
        assertQuery("CACHE TABLE test_cache_predicate WHERE p1 <> 0", "VALUES('OK')");
        resultCachePushdown = computeActual(sessionCachePushdown, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        assertEquals(resultNormal.getMaterializedRows(), resultCachePushdown.getMaterializedRows());
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) TestingSession(io.prestosql.testing.TestingSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 23 with Session

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

the class AbstractTestDistributedQueries method testDisjunctPredicateWithPartitionKey.

@Test
public void testDisjunctPredicateWithPartitionKey() {
    if (supportsPushdown()) {
        assertUpdate("CREATE TABLE test_partition_predicate (id int, p1 char, p2 int) WITH (partitioned_by=ARRAY['p2'])");
        assertTrue(getQueryRunner().tableExists(getSession(), "test_partition_predicate"));
        assertTableColumnNames("test_partition_predicate", "id", "p1", "p2");
        assertUpdate("INSERT INTO test_partition_predicate VALUES (1,'a',1), (2,'b',2), (3,'c',3)", 3);
        assertUpdate("INSERT INTO test_partition_predicate VALUES (4,'d',4), (5,'e',5), (6,'f',6)", 3);
        assertUpdate("INSERT INTO test_partition_predicate VALUES (7,'g',7), (8,'h',8), (9,'i',9)", 3);
        String sql = "SELECT id, p1, p2 FROM test_partition_predicate WHERE id > 0 and (p1='b' or p2>3) ORDER BY id";
        assertQuery(getSession(), sql, "VALUES (2,'b',2), (4,'d',4), (5,'e',5), (6,'f',6), (7,'g',7), (8,'h',8), (9,'i',9)");
        Session session1 = Session.builder(getSession()).setCatalogSessionProperty(getSession().getCatalog().get(), "orc_predicate_pushdown_enabled", "true").setCatalogSessionProperty(getSession().getCatalog().get(), "orc_row_data_cache_enabled", "false").build();
        assertQuery(session1, sql, "VALUES (2,'b',2), (4,'d',4), (5,'e',5), (6,'f',6), (7,'g',7), (8,'h',8), (9,'i',9)");
        assertUpdate("INSERT INTO test_partition_predicate VALUES (10,'j',10)", 1);
        assertQuery(session1, sql, "VALUES (2,'b',2), (4,'d',4), (5,'e',5), (6,'f',6), (7,'g',7), (8,'h',8), (9,'i',9), (10,'j',10)");
        assertUpdate("INSERT INTO test_partition_predicate VALUES (11,NULL,11), (12,NULL,NULL), (NULL,NULL,NULL)", 3);
        /* NUlls Excluded */
        MaterializedResult resultNormal = computeActual(sql);
        MaterializedResult resultPushdown = computeActual(session1, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        /* NUlls Included */
        sql = "SELECT id, p1, p2 FROM test_partition_predicate WHERE id > 0 and (p1 IS NULL or p2<3) ORDER BY id, p1";
        resultPushdown = computeActual(session1, sql);
        resultNormal = computeActual(sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        /* Query Test with Cache */
        Session session2 = Session.builder(getSession()).setCatalogSessionProperty(getSession().getCatalog().get(), "orc_predicate_pushdown_enabled", "true").setCatalogSessionProperty(getSession().getCatalog().get(), "orc_row_data_cache_enabled", "true").build();
        assertQuery(session2, "CACHE TABLE test_partition_predicate WHERE p2 > 0", "VALUES ('OK')");
        MaterializedResult resultCachePushdown = computeActual(session2, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultCachePushdown.getMaterializedRows());
        sql = "SELECT id, p1, p2 FROM test_partition_predicate WHERE id > 0 and (p1 IS NULL or p2 IS NULL) ORDER BY id";
        resultNormal = computeActual(sql);
        resultPushdown = computeActual(session1, sql);
        resultCachePushdown = computeActual(session2, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        assertEquals(resultNormal.getMaterializedRows(), resultCachePushdown.getMaterializedRows());
        sql = "SELECT id, p1, p2 FROM test_partition_predicate WHERE id > 0 and (p1 IS NOT NULL or p2 IS NULL) ORDER BY id";
        resultNormal = computeActual(sql);
        resultPushdown = computeActual(session1, sql);
        resultCachePushdown = computeActual(session2, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        assertEquals(resultNormal.getMaterializedRows(), resultCachePushdown.getMaterializedRows());
        sql = "SELECT id, p1, p2 FROM test_partition_predicate WHERE id > 0 and (p1 > 'e' OR p2 IS NULL) ORDER BY id";
        resultNormal = computeActual(sql);
        resultPushdown = computeActual(session1, sql);
        resultCachePushdown = computeActual(session2, sql);
        assertEquals(resultNormal.getMaterializedRows(), resultPushdown.getMaterializedRows());
        assertEquals(resultNormal.getMaterializedRows(), resultCachePushdown.getMaterializedRows());
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) TestingSession(io.prestosql.testing.TestingSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 24 with Session

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

the class AbstractTestOrderByQueries method testUndistributedOrderBy.

@Test
public void testUndistributedOrderBy() {
    Session undistributedOrderBy = Session.builder(getSession()).setSystemProperty(DISTRIBUTED_SORT, "false").build();
    assertQueryOrdered(undistributedOrderBy, "SELECT orderstatus FROM orders ORDER BY orderstatus");
}
Also used : Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 25 with Session

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

the class AbstractTestQueries method testExplainExecuteWithUsing.

@Test
public void testExplainExecuteWithUsing() {
    Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SELECT * FROM orders WHERE orderkey < ?").build();
    MaterializedResult result = computeActual(session, "EXPLAIN (TYPE LOGICAL) EXECUTE my_query USING 7");
    assertEquals(getOnlyElement(result.getOnlyColumnAsSet()), getExplainPlan("SELECT * FROM orders WHERE orderkey < 7", LOGICAL));
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) 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