@VisibleForTesting
    static double calculateNullsFractionForPartitioningKey(
            HiveColumnHandle column,
            List<HivePartition> partitions,
            Map<String, PartitionStatistics> statistics,
            double averageRowsPerPartition,
            double rowCount)
    {
        if (rowCount == 0) {
            return 0;
        }
        double estimatedNullsCount = partitions.stream()
                .filter(partition -> partition.getKeys().get(column).isNull())
                .map(HivePartition::getPartitionId)
                .mapToDouble(partitionName -> getPartitionRowCount(partitionName.getPartitionName(), statistics).orElse(averageRowsPerPartition))
                .sum();
        return normalizeFraction(estimatedNullsCount / rowCount);
    }
@Test
    public void testCalculateNullsFractionForPartitioningKey()
    {
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=string1/p2=1234")),
                        ImmutableMap.of("p1=string1/p2=1234", rowsCount(1000)),
                        2000,
                        0),
                0.0);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=string1/p2=1234")),
                        ImmutableMap.of("p1=string1/p2=1234", rowsCount(1000)),
                        2000,
                        4000),
                0.0);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234")),
                        ImmutableMap.of("p1=__HIVE_DEFAULT_PARTITION__/p2=1234", rowsCount(1000)),
                        2000,
                        4000),
                0.25);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234")),
                        ImmutableMap.of("p1=__HIVE_DEFAULT_PARTITION__/p2=1234", PartitionStatistics.empty()),
                        2000,
                        4000),
                0.5);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234")),
                        ImmutableMap.of(),
                        2000,
                        4000),
                0.5);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234"), partition("p1=__HIVE_DEFAULT_PARTITION__/p2=4321")),
                        ImmutableMap.of("p1=__HIVE_DEFAULT_PARTITION__/p2=1234", rowsCount(1000), "p1=__HIVE_DEFAULT_PARTITION__/p2=4321", rowsCount(2000)),
                        3000,
                        4000),
                0.75);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234"), partition("p1=__HIVE_DEFAULT_PARTITION__/p2=4321")),
                        ImmutableMap.of("p1=__HIVE_DEFAULT_PARTITION__/p2=1234", rowsCount(1000), "p1=__HIVE_DEFAULT_PARTITION__/p2=4321", PartitionStatistics.empty()),
                        3000,
                        4000),
                1.0);
        assertEquals(
                calculateNullsFractionForPartitioningKey(
                        PARTITION_COLUMN_1,
                        ImmutableList.of(partition("p1=__HIVE_DEFAULT_PARTITION__/p2=1234"), partition("p1=__HIVE_DEFAULT_PARTITION__/p2=4321")),
                        ImmutableMap.of("p1=__HIVE_DEFAULT_PARTITION__/p2=1234", rowsCount(1000), "p1=__HIVE_DEFAULT_PARTITION__/p2=4321", PartitionStatistics.empty()),
                        4000,
                        4000),
                1.0);
    }