use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestStarTreeQueries method testCubePredicateTimestampType.
@Test
public void testCubePredicateTimestampType() {
computeActual("CREATE TABLE timestamp_test_table (cint_1 int, cint_2 int, cint_3 int, cint_4 int, time_stamp TIMESTAMP)");
computeActual("INSERT INTO timestamp_test_table (cint_1, cint_2, cint_3, cint_4, time_stamp) VALUES (4, 8 ,9 ,10 , timestamp '2021-03-15 15:20:00')");
computeActual("CREATE CUBE timestamp_test_table_cube_1 ON timestamp_test_table " + "WITH (AGGREGATIONS=(count(*))," + " group=(time_stamp, cint_1), format= 'orc', partitioned_by = ARRAY['cint_1'])");
computeActual("INSERT INTO CUBE timestamp_test_table_cube_1 where time_stamp = timestamp '2021-03-15 15:20:00'");
MaterializedResult result = computeActual("SHOW CUBES FOR timestamp_test_table");
MaterializedRow matchingRow = result.getMaterializedRows().stream().filter(row -> row.getField(1).toString().contains("timestamp_test_table_cube_1")).findFirst().orElse(null);
assertNotNull(matchingRow);
matchingRow = result.getMaterializedRows().stream().filter(row -> row.getField(5).toString().contains("TIMESTAMP '2021-03-15 15:20:00.000'")).findFirst().orElse(null);
assertNotNull(matchingRow);
assertEquals(matchingRow.getField(2), "Active");
assertUpdate("DROP CUBE timestamp_test_table_cube_1");
assertUpdate("DROP TABLE timestamp_test_table");
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestQueries method testTableSampleBernoulli.
@Test
public void testTableSampleBernoulli() {
DescriptiveStatistics stats = new DescriptiveStatistics();
int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows().size();
for (int i = 0; i < 100; i++) {
List<MaterializedRow> values = computeActual("SELECT orderkey FROM orders TABLESAMPLE BERNOULLI (50)").getMaterializedRows();
assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
stats.addValue(values.size() * 1.0 / total);
}
double mean = stats.getGeometricMean();
assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean));
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestQueries method testShowSession.
@Test
public void testShowSession() {
Session session = new Session(getSession().getQueryId(), Optional.empty(), getSession().isClientTransactionSupport(), getSession().getIdentity(), getSession().getSource(), getSession().getCatalog(), getSession().getSchema(), getSession().getPath(), getSession().getTraceToken(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(), getSession().getUserAgent(), getSession().getClientInfo(), getSession().getClientTags(), getSession().getClientCapabilities(), getSession().getResourceEstimates(), getSession().getStartTime(), ImmutableMap.<String, String>builder().put("test_string", "foo string").put("test_long", "424242").build(), ImmutableMap.of(), ImmutableMap.of(TESTING_CATALOG, ImmutableMap.<String, String>builder().put("connector_string", "bar string").put("connector_long", "11").build()), getQueryRunner().getMetadata().getSessionPropertyManager(), getSession().getPreparedStatements(), getSession().isPageMetadataEnabled());
MaterializedResult result = computeActual(session, "SHOW SESSION");
ImmutableMap<String, MaterializedRow> properties = Maps.uniqueIndex(result.getMaterializedRows(), input -> {
assertEquals(input.getFieldCount(), 5);
return (String) input.getField(0);
});
assertEquals(properties.get("test_string"), new MaterializedRow(1, "test_string", "foo string", "test default", "varchar", "test string property"));
assertEquals(properties.get("test_long"), new MaterializedRow(1, "test_long", "424242", "42", "bigint", "test long property"));
assertEquals(properties.get(TESTING_CATALOG + ".connector_string"), new MaterializedRow(1, TESTING_CATALOG + ".connector_string", "bar string", "connector default", "varchar", "connector string property"));
assertEquals(properties.get(TESTING_CATALOG + ".connector_long"), new MaterializedRow(1, TESTING_CATALOG + ".connector_long", "11", "33", "bigint", "connector long property"));
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestQueries method testValuesWithTimestamp.
@Test
public void testValuesWithTimestamp() {
MaterializedResult actual = computeActual("VALUES (current_timestamp, now())");
List<MaterializedRow> rows = actual.getMaterializedRows();
assertEquals(rows.size(), 1);
MaterializedRow row = rows.get(0);
assertEquals(row.getField(0), row.getField(1));
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestQueries method testArrayShuffle.
@Test
public void testArrayShuffle() {
List<Integer> expected = IntStream.rangeClosed(1, 500).boxed().collect(toList());
Set<List<Integer>> distinctResults = new HashSet<>();
distinctResults.add(expected);
for (int i = 0; i < 3; i++) {
MaterializedResult results = computeActual(format("SELECT shuffle(ARRAY %s) FROM orders LIMIT 10", expected));
List<MaterializedRow> rows = results.getMaterializedRows();
assertEquals(rows.size(), 10);
for (MaterializedRow row : rows) {
List<Integer> actual = (List<Integer>) row.getField(0);
// check if the result is a correct permutation
assertEqualsIgnoreOrder(actual, expected);
distinctResults.add(actual);
}
}
assertTrue(distinctResults.size() >= 24, "shuffle must produce at least 24 distinct results");
}
Aggregations