Search in sources :

Example 66 with MaterializedRow

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

the class AbstractTestQueries method testApproxPercentile.

@Test
public void testApproxPercentile() {
    MaterializedResult raw = computeActual("SELECT orderstatus, orderkey, totalprice FROM orders");
    Multimap<String, Long> orderKeyByStatus = ArrayListMultimap.create();
    Multimap<String, Double> totalPriceByStatus = ArrayListMultimap.create();
    for (MaterializedRow row : raw.getMaterializedRows()) {
        orderKeyByStatus.put((String) row.getField(0), ((Number) row.getField(1)).longValue());
        totalPriceByStatus.put((String) row.getField(0), (Double) row.getField(2));
    }
    MaterializedResult actual = computeActual("" + "SELECT orderstatus, " + "   approx_percentile(orderkey, 0.5), " + "   approx_percentile(totalprice, 0.5)," + "   approx_percentile(orderkey, 2, 0.5)," + "   approx_percentile(totalprice, 2, 0.5)\n" + "FROM orders\n" + "GROUP BY orderstatus");
    for (MaterializedRow row : actual.getMaterializedRows()) {
        String status = (String) row.getField(0);
        Long orderKey = ((Number) row.getField(1)).longValue();
        Double totalPrice = (Double) row.getField(2);
        Long orderKeyWeighted = ((Number) row.getField(3)).longValue();
        Double totalPriceWeighted = (Double) row.getField(4);
        List<Long> orderKeys = Ordering.natural().sortedCopy(orderKeyByStatus.get(status));
        List<Double> totalPrices = Ordering.natural().sortedCopy(totalPriceByStatus.get(status));
        // verify real rank of returned value is within 1% of requested rank
        assertTrue(orderKey >= orderKeys.get((int) (0.49 * orderKeys.size())));
        assertTrue(orderKey <= orderKeys.get((int) (0.51 * orderKeys.size())));
        assertTrue(orderKeyWeighted >= orderKeys.get((int) (0.49 * orderKeys.size())));
        assertTrue(orderKeyWeighted <= orderKeys.get((int) (0.51 * orderKeys.size())));
        assertTrue(totalPrice >= totalPrices.get((int) (0.49 * totalPrices.size())));
        assertTrue(totalPrice <= totalPrices.get((int) (0.51 * totalPrices.size())));
        assertTrue(totalPriceWeighted >= totalPrices.get((int) (0.49 * totalPrices.size())));
        assertTrue(totalPriceWeighted <= totalPrices.get((int) (0.51 * totalPrices.size())));
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 67 with MaterializedRow

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

the class AbstractTestStarTreeQueries method testShowCubes.

@Test
public void testShowCubes() {
    computeActual("CREATE TABLE nation_show_cube_table_1 AS SELECT * FROM nation");
    assertUpdate(starTreeDisabledSession, "CREATE CUBE nation_show_cube_1 ON nation_show_cube_table_1 " + "WITH (AGGREGATIONS=(count(*), COUNT(distinct nationkey), count(distinct regionkey), avg(nationkey), count(regionkey), sum(regionkey)," + " min(regionkey), max(regionkey), max(nationkey), min(nationkey))," + " group=(nationkey), format= 'orc', partitioned_by = ARRAY['nationkey'])");
    assertUpdate(starTreeDisabledSession, "CREATE CUBE nation_show_cube_2 ON nation_show_cube_table_1 " + "WITH (AGGREGATIONS=(count(*), COUNT(distinct nationkey), count(distinct regionkey), avg(nationkey), count(regionkey), sum(regionkey)," + " min(regionkey), max(regionkey), max(nationkey), min(nationkey))," + " group=())");
    MaterializedResult result = computeActual("SHOW CUBES FOR nation_show_cube_table_1");
    MaterializedRow matchingRow1 = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_show_cube_1")).findFirst().orElse(null);
    assertNotNull(matchingRow1);
    assertTrue(matchingRow1.getFields().containsAll(ImmutableList.of("hive.tpch.nation_show_cube_1", "hive.tpch.nation_show_cube_table_1", "Inactive", "nationkey")));
    MaterializedRow matchingRow2 = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_show_cube_2")).findFirst().orElse(null);
    assertNotNull(matchingRow2);
    assertTrue(matchingRow2.getFields().containsAll(ImmutableList.of("hive.tpch.nation_show_cube_2", "hive.tpch.nation_show_cube_table_1", "Inactive", "")));
    result = computeActual("SHOW CUBES FOR nation_show_cube_table_1");
    assertEquals(result.getRowCount(), 2);
    matchingRow1 = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_show_cube_1")).findFirst().orElse(null);
    assertNotNull(matchingRow1);
    assertTrue(result.getMaterializedRows().get(0).getFields().containsAll(ImmutableList.of("hive.tpch.nation_show_cube_1", "hive.tpch.nation_show_cube_table_1", "Inactive", "nationkey")));
    matchingRow2 = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_show_cube_2")).findFirst().orElse(null);
    assertNotNull(matchingRow2);
    assertTrue(result.getMaterializedRows().get(1).getFields().containsAll(ImmutableList.of("hive.tpch.nation_show_cube_2", "hive.tpch.nation_show_cube_table_1", "Inactive", "")));
    assertUpdate("DROP CUBE nation_show_cube_1");
    assertUpdate("DROP CUBE nation_show_cube_2");
    assertUpdate("DROP TABLE nation_show_cube_table_1");
}
Also used : QueryAssertions.assertEqualsIgnoreOrder(io.prestosql.tests.QueryAssertions.assertEqualsIgnoreOrder) Arrays(java.util.Arrays) SystemSessionProperties(io.prestosql.SystemSessionProperties) Assert.assertEquals(org.testng.Assert.assertEquals) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) MaterializedResult(io.prestosql.testing.MaterializedResult) ImmutableList(com.google.common.collect.ImmutableList) Session(io.prestosql.Session) Assert.assertFalse(org.testng.Assert.assertFalse) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) TableScanNode(io.prestosql.spi.plan.TableScanNode) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Assert.assertNotNull(org.testng.Assert.assertNotNull) MaterializedRow(io.prestosql.testing.MaterializedRow) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) PlanNodeSearcher(io.prestosql.sql.planner.optimizations.PlanNodeSearcher) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 68 with MaterializedRow

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

the class AbstractTestStarTreeQueries method testCubeStatusChange.

@Test
public void testCubeStatusChange() {
    computeActual("CREATE TABLE nation_table_status_test AS SELECT * FROM nation");
    assertUpdate("CREATE CUBE nation_status_cube_1 ON nation_table_status_test " + "WITH (AGGREGATIONS=(count(*), COUNT(distinct nationkey), count(distinct regionkey), avg(nationkey), count(regionkey), sum(regionkey)," + " min(regionkey), max(regionkey), max(nationkey), min(nationkey))," + " group=(nationkey), format= 'orc', partitioned_by = ARRAY['nationkey'])");
    MaterializedResult result = computeActual("SHOW CUBES FOR nation_table_status_test");
    MaterializedRow matchingRow = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_status_cube_1")).findFirst().orElse(null);
    assertNotNull(matchingRow);
    assertEquals(matchingRow.getField(2), "Inactive");
    assertUpdate("INSERT INTO CUBE nation_status_cube_1 where nationkey > 5", 19);
    result = computeActual("SHOW CUBES FOR nation_table_status_test");
    matchingRow = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("nation_status_cube_1")).findFirst().orElse(null);
    assertNotNull(matchingRow);
    assertEquals(matchingRow.getField(2), "Active");
    assertUpdate("DROP CUBE nation_status_cube_1");
    assertUpdate("DROP TABLE nation_table_status_test");
}
Also used : QueryAssertions.assertEqualsIgnoreOrder(io.prestosql.tests.QueryAssertions.assertEqualsIgnoreOrder) Arrays(java.util.Arrays) SystemSessionProperties(io.prestosql.SystemSessionProperties) Assert.assertEquals(org.testng.Assert.assertEquals) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) MaterializedResult(io.prestosql.testing.MaterializedResult) ImmutableList(com.google.common.collect.ImmutableList) Session(io.prestosql.Session) Assert.assertFalse(org.testng.Assert.assertFalse) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) TableScanNode(io.prestosql.spi.plan.TableScanNode) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Assert.assertNotNull(org.testng.Assert.assertNotNull) MaterializedRow(io.prestosql.testing.MaterializedRow) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) PlanNodeSearcher(io.prestosql.sql.planner.optimizations.PlanNodeSearcher) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 69 with MaterializedRow

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

the class AbstractTestStarTreeQueries method assertSSBQuery.

private void assertSSBQuery(@Language("SQL") String query, String cubeName) {
    MaterializedResult expectedResult = computeActualAndAssertPlan(starTreeDisabledSession, query, assertInTableScans("ssb_lineorder"));
    MaterializedResult actualResult = computeActualAndAssertPlan(starTreeEnabledSession, query, assertInTableScans(cubeName));
    List<MaterializedRow> actualRows = actualResult.getMaterializedRows();
    List<MaterializedRow> expectedRows = expectedResult.getMaterializedRows();
    assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + query + "\n:");
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 70 with MaterializedRow

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

the class AbstractTestQueries method testNonDeterministicAggregationPredicatePushdown.

@Test
public void testNonDeterministicAggregationPredicatePushdown() {
    MaterializedResult materializedResult = computeActual("" + "SELECT COUNT(*)\n" + "FROM (\n" + "  SELECT orderkey, COUNT(*)\n" + "  FROM lineitem\n" + "  GROUP BY orderkey\n" + "  LIMIT 1000\n" + ")\n" + "WHERE rand() > 0.5");
    MaterializedRow row = getOnlyElement(materializedResult.getMaterializedRows());
    assertEquals(row.getFieldCount(), 1);
    long count = (Long) row.getField(0);
    // Technically non-deterministic unit test but has essentially a next to impossible chance of a false positive
    assertTrue(count > 0 && count < 1000);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Aggregations

MaterializedRow (io.prestosql.testing.MaterializedRow)89 MaterializedResult (io.prestosql.testing.MaterializedResult)80 Test (org.testng.annotations.Test)57 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)18 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)16 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)14 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)14 Constraint (io.prestosql.spi.connector.Constraint)14 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)14 ImmutableList (com.google.common.collect.ImmutableList)13 HiveColumnHandle.bucketColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle)12 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)12 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)12 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)12 List (java.util.List)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 Session (io.prestosql.Session)9 Language (org.intellij.lang.annotations.Language)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Plan (io.prestosql.sql.planner.Plan)8