diff --git a/lib/trino-collect/src/main/java/io/trino/collect/cache/EmptyCache.java b/lib/trino-collect/src/main/java/io/trino/collect/cache/EmptyCache.java index 0856264ea5d3..7ad5646fb24d 100644 --- a/lib/trino-collect/src/main/java/io/trino/collect/cache/EmptyCache.java +++ b/lib/trino-collect/src/main/java/io/trino/collect/cache/EmptyCache.java @@ -15,7 +15,9 @@ import com.google.common.cache.AbstractLoadingCache; import com.google.common.cache.CacheLoader; +import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheStats; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.UncheckedExecutionException; @@ -59,6 +61,33 @@ public V get(K key) return get(key, () -> loader.load(key)); } + @Override + public ImmutableMap getAll(Iterable keys) + throws ExecutionException + { + try { + Set keySet = ImmutableSet.copyOf(keys); + statsCounter.recordMisses(keySet.size()); + @SuppressWarnings("unchecked") // safe since all keys extend K + ImmutableMap result = (ImmutableMap) loader.loadAll(keySet); + for (K key : keySet) { + if (!result.containsKey(key)) { + throw new InvalidCacheLoadException("loadAll failed to return a value for " + key); + } + } + statsCounter.recordLoadSuccess(1); + return result; + } + catch (RuntimeException e) { + statsCounter.recordLoadException(1); + throw new UncheckedExecutionException(e); + } + catch (Exception e) { + statsCounter.recordLoadException(1); + throw new ExecutionException(e); + } + } + @Override public V get(K key, Callable valueLoader) throws ExecutionException diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastore.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastore.java index 31c96c28debe..fca80002e971 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastore.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastore.java @@ -492,8 +492,11 @@ public void testGetTableStatistics() assertEquals(metastore.getTableStatistics(table), TEST_STATS); assertEquals(mockClient.getAccessCount(), 2); - assertEquals(metastore.getTableStatisticsStats().getRequestCount(), 1); - assertEquals(metastore.getTableStatisticsStats().getHitRate(), 0.0); + assertEquals(metastore.getTableStatistics(table), TEST_STATS); + assertEquals(mockClient.getAccessCount(), 2); + + assertEquals(metastore.getTableStatisticsStats().getRequestCount(), 2); + assertEquals(metastore.getTableStatisticsStats().getHitRate(), 0.5); assertEquals(metastore.getTableStats().getRequestCount(), 2); assertEquals(metastore.getTableStats().getHitRate(), 0.5); @@ -513,8 +516,11 @@ public void testGetPartitionStatistics() assertEquals(metastore.getPartitionStatistics(table, ImmutableList.of(partition)), ImmutableMap.of(TEST_PARTITION1, TEST_STATS)); assertEquals(mockClient.getAccessCount(), 3); - assertEquals(metastore.getPartitionStatisticsStats().getRequestCount(), 1); - assertEquals(metastore.getPartitionStatisticsStats().getHitRate(), 0.0); + assertEquals(metastore.getPartitionStatistics(table, ImmutableList.of(partition)), ImmutableMap.of(TEST_PARTITION1, TEST_STATS)); + assertEquals(mockClient.getAccessCount(), 3); + + assertEquals(metastore.getPartitionStatisticsStats().getRequestCount(), 2); + assertEquals(metastore.getPartitionStatisticsStats().getHitRate(), 0.5); assertEquals(metastore.getTableStats().getRequestCount(), 3); assertEquals(metastore.getTableStats().getHitRate(), 2.0 / 3);