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