Search in sources :

Example 76 with MaterializedRow

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");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Constraint(com.facebook.presto.spi.Constraint) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 77 with MaterializedRow

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);
    }
}
Also used : Duration(io.airlift.units.Duration) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Plan(com.facebook.presto.sql.planner.Plan) MaterializedResultWithPlan(com.facebook.presto.testing.QueryRunner.MaterializedResultWithPlan) MaterializedResultWithPlan(com.facebook.presto.testing.QueryRunner.MaterializedResultWithPlan) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 78 with MaterializedRow

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);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 79 with MaterializedRow

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);
}
Also used : List(java.util.List) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 80 with MaterializedRow

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);
}
Also used : MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Aggregations

MaterializedRow (com.facebook.presto.testing.MaterializedRow)91 MaterializedResult (com.facebook.presto.testing.MaterializedResult)80 Test (org.testng.annotations.Test)67 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)31 ImmutableList (com.google.common.collect.ImmutableList)16 Constraint (com.facebook.presto.spi.Constraint)15 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Language (org.intellij.lang.annotations.Language)13 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)12 List (java.util.List)11 Session (com.facebook.presto.Session)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)10 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)9 UUID (java.util.UUID)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 ImmutableMap (com.google.common.collect.ImmutableMap)8