Search in sources :

Example 6 with MaterializedRow

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");
}
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 7 with MaterializedRow

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));
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 8 with MaterializedRow

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"));
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 9 with MaterializedRow

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

Example 10 with MaterializedRow

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");
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) HashSet(java.util.HashSet) 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