@VisibleForTesting
    static OptionalDouble calculateAverageSizePerPartition(Collection<PartitionStatistics> statistics)
    {
        return statistics.stream()
                .map(PartitionStatistics::getBasicStatistics)
                .map(HiveBasicStatistics::getInMemoryDataSizeInBytes)
                .filter(OptionalLong::isPresent)
                .mapToLong(OptionalLong::getAsLong)
                .peek(size -> verify(size >= 0, "size must be greater than or equal to zero"))
                .average();
    }
@Test
    public void testCalculateAverageSizePerPartition()
    {
        assertThat(calculateAverageSizePerPartition(ImmutableList.of())).isEmpty();
        assertThat(calculateAverageSizePerPartition(ImmutableList.of(PartitionStatistics.empty()))).isEmpty();
        assertThat(calculateAverageSizePerPartition(ImmutableList.of(PartitionStatistics.empty(), PartitionStatistics.empty()))).isEmpty();
        assertEquals(calculateAverageSizePerPartition(ImmutableList.of(inMemorySize(10))), OptionalDouble.of(10));
        assertEquals(calculateAverageSizePerPartition(ImmutableList.of(inMemorySize(10), PartitionStatistics.empty())), OptionalDouble.of(10));
        assertEquals(calculateAverageSizePerPartition(ImmutableList.of(inMemorySize(10), inMemorySize(20))), OptionalDouble.of(15));
        assertEquals(calculateAverageSizePerPartition(ImmutableList.of(inMemorySize(10), inMemorySize(20), PartitionStatistics.empty())), OptionalDouble.of(15));
    }