Search in sources :

Example 1 with Row

use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.

the class TestCsv method assertSelect.

private static void assertSelect(String query, String tableName) {
    QueryResult expected = onTrino().executeQuery(format(query, "tpch.tiny.nation"));
    List<Row> expectedRows = expected.rows().stream().map(columns -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = onTrino().executeQuery(format(query, tableName));
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsOnly(expectedRows);
}
Also used : Flaky(io.trino.testng.services.Flaky) HMS_ONLY(io.trino.tests.product.TestGroups.HMS_ONLY) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QueryAssert.assertThat(io.trino.tempto.assertions.QueryAssert.assertThat) ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE) QueryExecutors.onHive(io.trino.tests.product.utils.QueryExecutors.onHive) ProductTest(io.trino.tempto.ProductTest) Test(org.testng.annotations.Test) QueryResult(io.trino.tempto.query.QueryResult) QueryExecutors.onTrino(io.trino.tests.product.utils.QueryExecutors.onTrino) String.format(java.lang.String.format) List(java.util.List) ERROR_COMMITTING_WRITE_TO_HIVE_MATCH(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_MATCH) Row.row(io.trino.tempto.assertions.QueryAssert.Row.row) Row(io.trino.tempto.assertions.QueryAssert.Row) STORAGE_FORMATS(io.trino.tests.product.TestGroups.STORAGE_FORMATS) QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row)

Example 2 with Row

use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.

the class TestHiveCaching method testReadFromTable.

private void testReadFromTable(String tableNameSuffix) {
    String cachedTableName = "hive.default.test_cache_read" + tableNameSuffix;
    String nonCachedTableName = "hivenoncached.default.test_cache_read" + tableNameSuffix;
    Row[] tableData = createTestTable(nonCachedTableName);
    CacheStats beforeCacheStats = getCacheStats();
    long initialRemoteReads = beforeCacheStats.getRemoteReads();
    long initialCachedReads = beforeCacheStats.getCachedReads();
    long initialNonLocalReads = beforeCacheStats.getNonLocalReads();
    long initialAsyncDownloadedMb = beforeCacheStats.getAsyncDownloadedMb();
    assertThat(onTrino().executeQuery("SELECT * FROM " + cachedTableName)).containsExactlyInOrder(tableData);
    assertEventually(new Duration(20, SECONDS), () -> {
        // first query via caching catalog should fetch remote data
        CacheStats afterQueryCacheStats = getCacheStats();
        assertGreaterThanOrEqual(afterQueryCacheStats.getAsyncDownloadedMb(), initialAsyncDownloadedMb + 5);
        assertGreaterThan(afterQueryCacheStats.getRemoteReads(), initialRemoteReads);
        assertEquals(afterQueryCacheStats.getCachedReads(), initialCachedReads);
        assertEquals(afterQueryCacheStats.getNonLocalReads(), initialNonLocalReads);
    });
    assertEventually(new Duration(10, SECONDS), () -> {
        CacheStats beforeQueryCacheStats = getCacheStats();
        long beforeQueryCachedReads = beforeQueryCacheStats.getCachedReads();
        long beforeQueryRemoteReads = beforeQueryCacheStats.getRemoteReads();
        long beforeQueryNonLocalReads = beforeQueryCacheStats.getNonLocalReads();
        assertThat(onTrino().executeQuery("SELECT * FROM " + cachedTableName)).containsExactlyInOrder(tableData);
        // query via caching catalog should read exclusively from cache
        CacheStats afterQueryCacheStats = getCacheStats();
        assertGreaterThan(afterQueryCacheStats.getCachedReads(), beforeQueryCachedReads);
        assertEquals(afterQueryCacheStats.getRemoteReads(), beforeQueryRemoteReads);
        // all reads should be local as Trino would schedule splits on nodes with cached data
        assertEquals(afterQueryCacheStats.getNonLocalReads(), beforeQueryNonLocalReads);
    });
    onTrino().executeQuery("DROP TABLE " + nonCachedTableName);
}
Also used : CachingTestUtils.getCacheStats(io.trino.tests.product.hive.util.CachingTestUtils.getCacheStats) CacheStats(io.trino.tests.product.hive.util.CachingTestUtils.CacheStats) Duration(io.airlift.units.Duration) Row(io.trino.tempto.assertions.QueryAssert.Row)

Example 3 with Row

use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.

the class TestHiveCaching method createTestTable.

/**
 * Creates table with 5 text files that are larger than 1MB
 */
private Row[] createTestTable(String tableName) {
    StringBuilder randomDataBuilder = new StringBuilder();
    Random random = new Random();
    for (int i = 0; i < 500_000; ++i) {
        randomDataBuilder.append(random.nextInt(10));
    }
    String randomData = randomDataBuilder.toString();
    onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName);
    onTrino().executeQuery("CREATE TABLE " + tableName + " (col varchar) WITH (format='TEXTFILE')");
    for (int i = 0; i < NUMBER_OF_FILES; ++i) {
        // use `format` to overcome SQL query length limit
        onTrino().executeQuery("INSERT INTO " + tableName + " SELECT format('%1$s%1$s%1$s%1$s%1$s', '" + randomData + "')");
    }
    Row row = row(randomData.repeat(5));
    return Collections.nCopies(NUMBER_OF_FILES, row).toArray(new Row[0]);
}
Also used : Random(java.util.Random) Row(io.trino.tempto.assertions.QueryAssert.Row)

Example 4 with Row

use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.

the class TestHivePropertiesTable method testTrinoViewPropertiesTable.

@Test
public void testTrinoViewPropertiesTable() throws Exception {
    onTrino().executeQuery("DROP TABLE IF EXISTS test_trino_view_properties_base");
    onTrino().executeQuery("DROP VIEW IF EXISTS test_trino_view_properties");
    onTrino().executeQuery("CREATE TABLE test_trino_view_properties_base (col INT)");
    onTrino().executeQuery("CREATE VIEW test_trino_view_properties AS SELECT * FROM test_trino_view_properties_base");
    assertThat(onTrino().executeQuery("SHOW COLUMNS FROM \"test_trino_view_properties$properties\"")).containsExactlyInOrder(row("comment", "varchar", "", ""), row("presto_query_id", "varchar", "", ""), row("presto_version", "varchar", "", ""), row("presto_view", "varchar", "", ""), row("transient_lastddltime", "varchar", "", ""), row("trino_created_by", "varchar", "", ""));
    assertThat(onTrino().executeQuery("SELECT * FROM \"test_trino_view_properties$properties\"")).hasRowsCount(1).containsExactlyInOrder(new Row(getTablePropertiesOnHive("test_trino_view_properties")));
    onTrino().executeQuery("DROP VIEW IF EXISTS test_trino_view_properties");
    onTrino().executeQuery("DROP TABLE IF EXISTS test_trino_view_properties_base");
}
Also used : Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test)

Example 5 with Row

use of io.trino.tempto.assertions.QueryAssert.Row in project trino by trinodb.

the class TestHivePropertiesTable method testHiveViewPropertiesTable.

@Test(groups = HIVE_VIEWS)
public void testHiveViewPropertiesTable() throws Exception {
    onTrino().executeQuery("DROP TABLE IF EXISTS test_hive_view_properties_base");
    onTrino().executeQuery("DROP VIEW IF EXISTS test_hive_view_properties");
    onTrino().executeQuery("CREATE TABLE test_hive_view_properties_base (col INT)");
    onHive().executeQuery("CREATE VIEW test_hive_view_properties AS SELECT * FROM test_hive_view_properties_base");
    // Use "contains" method because the table properties for Hive views aren't identical among testing environments
    assertThat(onTrino().executeQuery("SHOW COLUMNS FROM \"test_hive_view_properties$properties\"")).contains(row("transient_lastddltime", "varchar", "", ""));
    assertThat(onTrino().executeQuery("SELECT * FROM \"test_hive_view_properties$properties\"")).hasRowsCount(1).containsExactlyInOrder(new Row(getTablePropertiesOnHive("test_hive_view_properties")));
    onTrino().executeQuery("DROP VIEW IF EXISTS test_hive_view_properties");
    onTrino().executeQuery("DROP TABLE IF EXISTS test_hive_view_properties_base");
}
Also used : Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test)

Aggregations

Row (io.trino.tempto.assertions.QueryAssert.Row)19 Test (org.testng.annotations.Test)16 ProductTest (io.trino.tempto.ProductTest)14 QueryResult (io.trino.tempto.query.QueryResult)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Row.row (io.trino.tempto.assertions.QueryAssert.Row.row)3 QueryAssert.assertThat (io.trino.tempto.assertions.QueryAssert.assertThat)3 QueryExecutionException (io.trino.tempto.query.QueryExecutionException)3 Flaky (io.trino.testng.services.Flaky)3 HMS_ONLY (io.trino.tests.product.TestGroups.HMS_ONLY)3 STORAGE_FORMATS (io.trino.tests.product.TestGroups.STORAGE_FORMATS)3 ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE (io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE)3 ERROR_COMMITTING_WRITE_TO_HIVE_MATCH (io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_MATCH)3 QueryExecutors.onHive (io.trino.tests.product.utils.QueryExecutors.onHive)3 QueryExecutors.onTrino (io.trino.tests.product.utils.QueryExecutors.onTrino)3 String.format (java.lang.String.format)3 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)2 Splitter (com.google.common.base.Splitter)2 Verify.verify (com.google.common.base.Verify.verify)2 ImmutableMap (com.google.common.collect.ImmutableMap)2