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");
}
}
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);
}
}
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);
}
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()));
}
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);
}
Aggregations