Search in sources :

Example 36 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class QueryAssertions method assertUpdate.

public static void assertUpdate(QueryRunner queryRunner, Session session, @Language("SQL") String sql, OptionalLong count) {
    long start = System.nanoTime();
    MaterializedResult results = queryRunner.execute(session, sql);
    log.info("FINISHED in presto: %s", nanosSince(start));
    if (!results.getUpdateType().isPresent()) {
        fail("update type is not set");
    }
    if (results.getUpdateCount().isPresent()) {
        if (!count.isPresent()) {
            fail("update count should not be present");
        }
        assertEquals(results.getUpdateCount().getAsLong(), count.getAsLong(), "update count");
    } else if (count.isPresent()) {
        fail("update count is not present");
    }
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 37 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class QueryAssertions method assertQuery.

public static void assertQuery(QueryRunner actualQueryRunner, Session session, @Language("SQL") String actual, H2QueryRunner h2QueryRunner, @Language("SQL") String expected, boolean ensureOrdering, boolean compareUpdate) {
    long start = System.nanoTime();
    MaterializedResult actualResults = null;
    try {
        actualResults = actualQueryRunner.execute(session, actual).toJdbcTypes();
    } catch (RuntimeException ex) {
        fail("Execution of 'actual' query failed: " + actual, ex);
    }
    Duration actualTime = nanosSince(start);
    long expectedStart = System.nanoTime();
    MaterializedResult expectedResults = null;
    try {
        expectedResults = h2QueryRunner.execute(session, expected, actualResults.getTypes());
    } catch (RuntimeException ex) {
        fail("Execution of 'expected' query failed: " + actual, ex);
    }
    log.info("FINISHED in presto: %s, h2: %s, total: %s", actualTime, nanosSince(expectedStart), nanosSince(start));
    if (actualResults.getUpdateType().isPresent() || actualResults.getUpdateCount().isPresent()) {
        if (!actualResults.getUpdateType().isPresent()) {
            fail("update count present without update type for query: \n" + actual);
        }
        if (!compareUpdate) {
            fail("update type should not be present (use assertUpdate) for query: \n" + actual);
        }
    }
    List<MaterializedRow> actualRows = actualResults.getMaterializedRows();
    List<MaterializedRow> expectedRows = expectedResults.getMaterializedRows();
    if (compareUpdate) {
        if (!actualResults.getUpdateType().isPresent()) {
            fail("update type not present for query: \n" + actual);
        }
        if (!actualResults.getUpdateCount().isPresent()) {
            fail("update count not present for query: \n" + actual);
        }
        assertEquals(actualRows.size(), 1, "For query: \n " + actual + "\n:");
        assertEquals(expectedRows.size(), 1, "For query: \n " + actual + "\n:");
        MaterializedRow row = expectedRows.get(0);
        assertEquals(row.getFieldCount(), 1, "For query: \n " + actual + "\n:");
        assertEquals(row.getField(0), actualResults.getUpdateCount().getAsLong(), "For query: \n " + actual + "\n:");
    }
    if (ensureOrdering) {
        if (!actualRows.equals(expectedRows)) {
            assertEquals(actualRows, expectedRows, "For query: \n " + actual + "\n:");
        }
    } else {
        assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
    }
}
Also used : Duration(io.airlift.units.Duration) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 38 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class AbstractTestQueries method testFullPrePartitionedWindowFunction.

@Test
public void testFullPrePartitionedWindowFunction() {
    MaterializedResult actual = computeActual("" + "SELECT orderkey, COUNT(*) OVER (PARTITION BY orderkey)\n" + "FROM (SELECT * FROM orders ORDER BY orderkey LIMIT 10)\n" + "ORDER BY orderkey LIMIT 5");
    MaterializedResult expected = resultBuilder(getSession(), BIGINT, BIGINT).row(1L, 1L).row(2L, 1L).row(3L, 1L).row(4L, 1L).row(5L, 1L).build();
    assertEquals(actual, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 39 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class AbstractTestQueries method testShowCatalogsLike.

@Test
public void testShowCatalogsLike() {
    MaterializedResult result = computeActual(format("SHOW CATALOGS LIKE '%s'", getSession().getCatalog().get()));
    assertEquals(result.getOnlyColumnAsSet(), ImmutableSet.of(getSession().getCatalog().get()));
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 40 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class AbstractTestQueries method testWindowFunctionsExpressions.

@SuppressWarnings("PointlessArithmeticExpression")
@Test
public void testWindowFunctionsExpressions() {
    MaterializedResult actual = computeActual("" + "SELECT orderkey, orderstatus\n" + ", row_number() OVER (ORDER BY orderkey * 2) *\n" + "  row_number() OVER (ORDER BY orderkey DESC) + 100\n" + "FROM (SELECT * FROM orders ORDER BY orderkey LIMIT 10) x\n" + "ORDER BY orderkey LIMIT 5");
    MaterializedResult expected = resultBuilder(getSession(), BIGINT, VARCHAR, BIGINT).row(1L, "O", (1L * 10) + 100).row(2L, "O", (2L * 9) + 100).row(3L, "F", (3L * 8) + 100).row(4L, "O", (4L * 7) + 100).row(5L, "F", (5L * 6) + 100).build();
    assertEquals(actual, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

MaterializedResult (com.facebook.presto.testing.MaterializedResult)298 Test (org.testng.annotations.Test)255 Page (com.facebook.presto.spi.Page)75 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)54 MaterializedRow (com.facebook.presto.testing.MaterializedRow)52 Type (com.facebook.presto.spi.type.Type)43 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)35 Session (com.facebook.presto.Session)23 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)21 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)20 ImmutableList (com.google.common.collect.ImmutableList)20 ColumnHandle (com.facebook.presto.spi.ColumnHandle)19 ConnectorSession (com.facebook.presto.spi.ConnectorSession)18 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)18 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)17 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)17 ImmutableMap (com.google.common.collect.ImmutableMap)17 List (java.util.List)17 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)16 Path (org.apache.hadoop.fs.Path)14