Search in sources :

Example 16 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class QueryAssertions method assertQuery.

public void assertQuery(@Language("SQL") String actual, @Language("SQL") String expected, boolean ensureOrdering) {
    MaterializedResult actualResults = null;
    try {
        actualResults = runner.execute(runner.getDefaultSession(), actual).toTestTypes();
    } catch (RuntimeException ex) {
        fail("Execution of 'actual' query failed: " + actual, ex);
    }
    MaterializedResult expectedResults = null;
    try {
        expectedResults = runner.execute(runner.getDefaultSession(), expected).toTestTypes();
    } catch (RuntimeException ex) {
        fail("Execution of 'expected' query failed: " + expected, ex);
    }
    assertEquals(actualResults.getTypes(), expectedResults.getTypes(), "Types mismatch for query: \n " + actual + "\n:");
    List<MaterializedRow> actualRows = actualResults.getMaterializedRows();
    List<MaterializedRow> expectedRows = expectedResults.getMaterializedRows();
    if (ensureOrdering) {
        if (!actualRows.equals(expectedRows)) {
            assertEquals(actualRows, expectedRows, "For query: \n " + actual + "\n:");
        }
    } else {
        assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
    }
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 17 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testShardingByTemporalDateColumn.

@Test
public void testShardingByTemporalDateColumn() {
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);
    assertUpdate("CREATE TABLE test_shard_temporal_date " + "WITH (temporal_column = 'orderdate') AS " + "SELECT orderdate, orderkey " + "FROM orders " + "WHERE orderdate < date '1992-02-08'", "SELECT count(*) " + "FROM orders " + "WHERE orderdate < date '1992-02-08'");
    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date");
    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }
    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }
    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date", "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) LocalDate(java.time.LocalDate) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 18 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testTableStatsSystemTable.

@SuppressWarnings("OverlyStrongTypeCast")
@Test
public void testTableStatsSystemTable() {
    // basic sanity tests
    assertQuery("" + "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + "  AND table_name IN ('orders', 'lineitem')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + "SELECT 'tpch', 'lineitem', (SELECT count(*) FROM lineitem)");
    assertQuery("" + "SELECT\n" + "  bool_and(row_count >= shard_count)\n" + ", bool_and(update_time >= create_time)\n" + ", bool_and(table_version >= 1)\n" + "FROM system.table_stats\n" + "WHERE row_count > 0", "SELECT true, true, true");
    // create empty table
    assertUpdate("CREATE TABLE test_table_stats (x bigint)");
    @Language("SQL") String sql = "" + "SELECT create_time, update_time, table_version," + "  shard_count, row_count, uncompressed_size\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + "  AND table_name = 'test_table_stats'";
    MaterializedRow row = getOnlyElement(computeActual(sql).getMaterializedRows());
    LocalDateTime createTime = (LocalDateTime) row.getField(0);
    LocalDateTime updateTime1 = (LocalDateTime) row.getField(1);
    assertEquals(createTime, updateTime1);
    // table_version
    assertEquals(row.getField(2), 1L);
    // shard_count
    assertEquals(row.getField(3), 0L);
    // row_count
    assertEquals(row.getField(4), 0L);
    // uncompressed_size
    long size1 = (long) row.getField(5);
    // insert
    assertUpdate("INSERT INTO test_table_stats VALUES (1), (2), (3), (4)", 4);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime2 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime1, updateTime2);
    // table_version
    assertEquals(row.getField(2), 2L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 4L);
    // uncompressed_size
    long size2 = (long) row.getField(5);
    assertGreaterThan(size2, size1);
    // delete
    assertUpdate("DELETE FROM test_table_stats WHERE x IN (2, 4)", 2);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime3 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime2, updateTime3);
    // table_version
    assertEquals(row.getField(2), 3L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // uncompressed_Size
    long size3 = (long) row.getField(5);
    assertLessThan(size3, size2);
    // add column
    assertUpdate("ALTER TABLE test_table_stats ADD COLUMN y bigint");
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    assertLessThan(updateTime3, (LocalDateTime) row.getField(1));
    // table_version
    assertEquals(row.getField(2), 4L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // uncompressed_size
    assertEquals(row.getField(5), size3);
    // cleanup
    assertUpdate("DROP TABLE test_table_stats");
}
Also used : LocalDateTime(java.time.LocalDateTime) Language(org.intellij.lang.annotations.Language) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 19 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testShardUuidHiddenColumn.

@Test
public void testShardUuidHiddenColumn() {
    assertUpdate("CREATE TABLE test_shard_uuid AS SELECT orderdate, orderkey FROM orders", "SELECT count(*) FROM orders");
    MaterializedResult actualResults = computeActual("SELECT *, \"$shard_uuid\" FROM test_shard_uuid");
    assertEquals(actualResults.getTypes(), ImmutableList.of(DATE, BIGINT, SHARD_UUID_COLUMN_TYPE));
    UUID arbitraryUuid = null;
    for (MaterializedRow row : actualResults.getMaterializedRows()) {
        Object uuid = row.getField(2);
        assertInstanceOf(uuid, String.class);
        arbitraryUuid = UUID.fromString((String) uuid);
    }
    assertNotNull(arbitraryUuid);
    actualResults = computeActual(format("SELECT * FROM test_shard_uuid where \"$shard_uuid\" = '%s'", arbitraryUuid));
    assertNotEquals(actualResults.getMaterializedRows().size(), 0);
    actualResults = computeActual("SELECT * FROM test_shard_uuid where \"$shard_uuid\" = 'foo'");
    assertEquals(actualResults.getMaterializedRows().size(), 0);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) UUID(java.util.UUID) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 20 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testTableStatsSystemTableWithDeltaDelete.

@SuppressWarnings("OverlyStrongTypeCast")
@Test
public void testTableStatsSystemTableWithDeltaDelete() {
    // create empty table
    assertUpdate("CREATE TABLE test_table_stats_with_delta_delete (x bigint) WITH (table_supports_delta_delete = true)");
    @Language("SQL") String sql = "" + "SELECT create_time, update_time, table_version," + "  shard_count, row_count, uncompressed_size, delta_count\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + "  AND table_name = 'test_table_stats_with_delta_delete'";
    MaterializedRow row = getOnlyElement(computeActual(sql).getMaterializedRows());
    LocalDateTime createTime = (LocalDateTime) row.getField(0);
    LocalDateTime updateTime1 = (LocalDateTime) row.getField(1);
    assertEquals(createTime, updateTime1);
    // table_version
    assertEquals(row.getField(2), 1L);
    // shard_count
    assertEquals(row.getField(3), 0L);
    // row_count
    assertEquals(row.getField(4), 0L);
    // uncompressed_size
    long size1 = (long) row.getField(5);
    // insert
    assertUpdate("INSERT INTO test_table_stats_with_delta_delete VALUES (1), (2), (3), (4)", 4);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime2 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime1, updateTime2);
    // table_version
    assertEquals(row.getField(2), 2L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 4L);
    // delta_count
    assertGreaterThanOrEqual((Long) row.getField(6), 0L);
    // uncompressed_size
    long size2 = (long) row.getField(5);
    assertGreaterThan(size2, size1);
    // delete
    assertUpdate("DELETE FROM test_table_stats_with_delta_delete WHERE x IN (2, 4)", 2);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime3 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime2, updateTime3);
    // table_version
    assertEquals(row.getField(2), 3L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // delta_count
    assertGreaterThanOrEqual((Long) row.getField(6), 1L);
    // uncompressed_Size
    long size3 = (long) row.getField(5);
    // without compaction, the size will grow with delta delete
    assertGreaterThan(size3, size2);
    // add column
    assertUpdate("ALTER TABLE test_table_stats_with_delta_delete ADD COLUMN y bigint");
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    assertLessThan(updateTime3, (LocalDateTime) row.getField(1));
    // table_version
    assertEquals(row.getField(2), 4L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // uncompressed_size
    assertEquals(row.getField(5), size3);
    // cleanup
    assertUpdate("DROP TABLE test_table_stats_with_delta_delete");
}
Also used : LocalDateTime(java.time.LocalDateTime) Language(org.intellij.lang.annotations.Language) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Aggregations

MaterializedRow (com.facebook.presto.testing.MaterializedRow)91 MaterializedResult (com.facebook.presto.testing.MaterializedResult)80 Test (org.testng.annotations.Test)67 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)31 ImmutableList (com.google.common.collect.ImmutableList)16 Constraint (com.facebook.presto.spi.Constraint)15 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Language (org.intellij.lang.annotations.Language)13 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)12 List (java.util.List)11 Session (com.facebook.presto.Session)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)10 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)9 UUID (java.util.UUID)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 ImmutableMap (com.google.common.collect.ImmutableMap)8