use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testFileRenamingForPartitionedTable.
@Test
public void testFileRenamingForPartitionedTable() {
try {
// Create partitioned table
assertUpdate(Session.builder(getSession()).setCatalogSessionProperty(catalog, FILE_RENAMING_ENABLED, "true").setSystemProperty("scale_writers", "false").setSystemProperty("writer_min_size", "1MB").setSystemProperty("task_writer_count", "1").build(), "CREATE TABLE partitioned_ordering_table (orderkey, custkey, totalprice, orderdate, orderpriority, clerk, shippriority, comment, orderstatus)\n" + "WITH (partitioned_by = ARRAY['orderstatus'], preferred_ordering_columns = ARRAY['orderkey']) AS\n" + "SELECT orderkey, custkey, totalprice, orderdate, orderpriority, clerk, shippriority, comment, orderstatus FROM tpch.sf1.orders", (long) computeActual("SELECT count(*) FROM tpch.sf1.orders").getOnlyValue());
// Collect all file names
Map<String, List<Integer>> partitionFileNamesMap = new HashMap<>();
MaterializedResult partitionedResults = computeActual("SELECT DISTINCT \"$path\" FROM partitioned_ordering_table");
for (int i = 0; i < partitionedResults.getRowCount(); i++) {
MaterializedRow row = partitionedResults.getMaterializedRows().get(i);
Path pathName = new Path((String) row.getField(0));
String partitionName = pathName.getParent().toString();
String fileName = pathName.getName();
partitionFileNamesMap.putIfAbsent(partitionName, new ArrayList<>());
partitionFileNamesMap.get(partitionName).add(Integer.valueOf(fileName));
}
// Assert that file names are a continuous increasing sequence for all partitions
for (String partitionName : partitionFileNamesMap.keySet()) {
List<Integer> partitionedTableFileNames = partitionFileNamesMap.get(partitionName);
assertTrue(partitionedTableFileNames.size() > 0);
assertTrue(isIncreasingSequence(partitionedTableFileNames));
}
} finally {
assertUpdate("DROP TABLE IF EXISTS partitioned_ordering_table");
}
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class QueryAssertions method assertQuery.
private static void assertQuery(QueryRunner actualQueryRunner, Session session, @Language("SQL") String actual, ExpectedQueryRunner expectedQueryRunner, @Language("SQL") String expected, boolean ensureOrdering, boolean compareUpdate, Optional<Consumer<Plan>> planAssertion) {
long start = System.nanoTime();
MaterializedResult actualResults = null;
Plan queryPlan = null;
if (planAssertion.isPresent()) {
try {
MaterializedResultWithPlan resultWithPlan = actualQueryRunner.executeWithPlan(session, actual, WarningCollector.NOOP);
queryPlan = resultWithPlan.getQueryPlan();
actualResults = resultWithPlan.getMaterializedResult().toTestTypes();
} catch (RuntimeException ex) {
fail("Execution of 'actual' query failed: " + actual, ex);
}
} else {
try {
actualResults = actualQueryRunner.execute(session, actual).toTestTypes();
} catch (RuntimeException ex) {
fail("Execution of 'actual' query failed: " + actual, ex);
}
}
if (planAssertion.isPresent()) {
planAssertion.get().accept(queryPlan);
}
Duration actualTime = nanosSince(start);
long expectedStart = System.nanoTime();
MaterializedResult expectedResults = null;
try {
expectedResults = expectedQueryRunner.execute(session, expected, actualResults.getTypes());
} catch (RuntimeException ex) {
fail("Execution of 'expected' query failed: " + expected, ex);
}
Duration totalTime = nanosSince(start);
if (totalTime.compareTo(Duration.succinctDuration(1, SECONDS)) > 0) {
log.info("FINISHED in presto: %s, expected: %s, total: %s", actualTime, nanosSince(expectedStart), totalTime);
}
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.MaterializedRow in project presto by prestodb.
the class AbstractTestAggregations method testGroupByNanRow.
@Test
public void testGroupByNanRow() {
MaterializedResult actual = computeActual("SELECT a, b, c FROM (VALUES ROW(nan(), 1, 2), ROW(nan(), 1, 2)) t(a, b, c) GROUP BY 1, 2, 3");
List<MaterializedRow> actualRows = actual.getMaterializedRows();
assertEquals(actualRows.size(), 1);
assertTrue(Double.isNaN((Double) actualRows.get(0).getField(0)));
assertEquals(actualRows.get(0).getField(1), 1);
assertEquals(actualRows.get(0).getField(2), 2);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestAggregations method testGroupByNanArray.
@Test
public void testGroupByNanArray() {
MaterializedResult actual = computeActual("SELECT a FROM (VALUES (ARRAY[nan(), 2e0, 3e0]), (ARRAY[nan(), 2e0, 3e0])) t(a) GROUP BY a");
List<MaterializedRow> actualRows = actual.getMaterializedRows();
assertEquals(actualRows.size(), 1);
assertTrue(Double.isNaN(((List<Double>) actualRows.get(0).getField(0)).get(0)));
assertEquals(((List<Double>) actualRows.get(0).getField(0)).get(1), 2.0);
assertEquals(((List<Double>) actualRows.get(0).getField(0)).get(2), 3.0);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestJoinQueries method testJoinWithNonDeterministicLessThan.
@Test
public void testJoinWithNonDeterministicLessThan() {
MaterializedRow actualRow = getOnlyElement(computeActual("SELECT count(*) FROM " + "customer c1 JOIN customer c2 ON c1.nationkey=c2.nationkey " + "WHERE c1.custkey - RANDOM(CAST(c1.custkey AS BIGINT)) < c2.custkey").getMaterializedRows());
assertEquals(actualRow.getFieldCount(), 1);
// this should be around ~69000
long actualCount = (Long) actualRow.getField(0);
MaterializedRow expectedAtLeastRow = getOnlyElement(computeActual("SELECT count(*) FROM " + "customer c1 JOIN customer c2 ON c1.nationkey=c2.nationkey " + "WHERE c1.custkey < c2.custkey").getMaterializedRows());
assertEquals(expectedAtLeastRow.getFieldCount(), 1);
// this is exactly 45022
long expectedAtLeastCount = (Long) expectedAtLeastRow.getField(0);
// Technically non-deterministic unit test but has hopefully a next to impossible chance of a false positive
assertTrue(actualCount > expectedAtLeastCount);
}
Aggregations