Search in sources :

Example 1 with CacheStats

use of io.trino.tests.product.hive.util.CachingTestUtils.CacheStats 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)

Aggregations

Duration (io.airlift.units.Duration)1 Row (io.trino.tempto.assertions.QueryAssert.Row)1 CacheStats (io.trino.tests.product.hive.util.CachingTestUtils.CacheStats)1 CachingTestUtils.getCacheStats (io.trino.tests.product.hive.util.CachingTestUtils.getCacheStats)1