Search in sources :

Example 11 with MaterializedRow

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

the class TestMemorySelection method testIndexSingleColMultiOperatorsVerifyResults.

@Test(dataProvider = "memConIndexSingleColMultiOperators")
public void testIndexSingleColMultiOperatorsVerifyResults(String queryOperator) throws InterruptedException {
    assertQuerySucceeds("CREATE TABLE test_indexOperations WITH (sorted_by=ARRAY['custkey'], async_processing=false) AS SELECT * FROM tpch.tiny.orders");
    // get how many test keys there are
    long testKeys = queryOperator.chars().filter(c -> c == '#').count();
    // get custkeys
    List<Object> results = getResults("SELECT * from (SELECT custkey FROM test_indexOperations LIMIT " + testKeys + ") ORDER BY custkey ASC");
    String tmpQueryOperator = queryOperator;
    for (Object key : results) {
        tmpQueryOperator = tmpQueryOperator.replaceFirst("#", String.valueOf((long) key));
    }
    String predicateQuery = "SELECT count(distinct custkey) FROM test_indexOperations WHERE " + tmpQueryOperator;
    MaterializedResult result1 = computeActual(predicateQuery.replace("test_indexOperations", "tpch.tiny.orders"));
    MaterializedResult result2 = computeActual(predicateQuery);
    // Drop table for next use
    assertQuerySucceeds("DROP TABLE test_indexOperations");
    System.out.println(predicateQuery);
    ArrayList<String> data1 = new ArrayList<>();
    ArrayList<String> data2 = new ArrayList<>();
    for (MaterializedRow item1 : result1.getMaterializedRows()) {
        data1.add(item1.toString());
    }
    for (MaterializedRow item2 : result2.getMaterializedRows()) {
        data2.add(item2.toString());
    }
    Collections.sort(data1);
    Collections.sort(data2);
    System.out.println(data1.size());
    System.out.println();
    System.out.println(data2.size());
    assertEquals(data1, data2);
}
Also used : DataProvider(org.testng.annotations.DataProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) MaterializedRow(io.prestosql.testing.MaterializedRow) Pair(io.prestosql.spi.heuristicindex.Pair) MaterializedResult(io.prestosql.testing.MaterializedResult) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) AbstractTestQueryFramework(io.prestosql.tests.AbstractTestQueryFramework) Assert.assertEquals(io.prestosql.testing.assertions.Assert.assertEquals) List(java.util.List) Locale(java.util.Locale) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ArrayList(java.util.ArrayList) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 12 with MaterializedRow

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

the class TestMemorySelection method getSingleResult.

private Object getSingleResult(@Language("SQL") String sql) {
    MaterializedResult rows = computeActual(sql);
    assertTrue(rows.getRowCount() > 0);
    MaterializedRow materializedRow = rows.getMaterializedRows().get(0);
    int fieldCount = materializedRow.getFieldCount();
    assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
    Object value = materializedRow.getField(0);
    return value;
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 13 with MaterializedRow

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

the class TestMemorySelection method getResults.

private List<Object> getResults(@Language("SQL") String sql) {
    MaterializedResult rows = computeActual(sql);
    List<Object> values = new ArrayList<>();
    for (MaterializedRow materializedRow : rows.getMaterializedRows()) {
        int fieldCount = materializedRow.getFieldCount();
        assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
        values.add(materializedRow.getField(0));
    }
    return values;
}
Also used : ArrayList(java.util.ArrayList) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 14 with MaterializedRow

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

the class TestMemorySmoke method assertQueryResult.

private void assertQueryResult(@Language("SQL") String sql, Object... expected) {
    MaterializedResult rows = computeActual(sql);
    assertEquals(rows.getRowCount(), expected.length);
    for (int i = 0; i < expected.length; i++) {
        MaterializedRow materializedRow = rows.getMaterializedRows().get(i);
        int fieldCount = materializedRow.getFieldCount();
        assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
        Object value = materializedRow.getField(0);
        assertEquals(value, expected[i]);
        assertTrue(materializedRow.getFieldCount() == 1);
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 15 with MaterializedRow

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

the class TestMemorySelection method assertQueryResult.

private void assertQueryResult(@Language("SQL") String sql, Object... expected) {
    MaterializedResult rows = computeActual(sql);
    assertEquals(rows.getRowCount(), expected.length);
    for (int i = 0; i < expected.length; i++) {
        MaterializedRow materializedRow = rows.getMaterializedRows().get(i);
        int fieldCount = materializedRow.getFieldCount();
        assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
        Object value = materializedRow.getField(0);
        assertEquals(value, expected[i]);
        assertTrue(materializedRow.getFieldCount() == 1);
    }
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

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