@VisibleForTesting
    static void validatePartitionStatistics(SchemaTableName table, Map<String, PartitionStatistics> partitionStatistics)
    {
        partitionStatistics.forEach((partition, statistics) -> {
            HiveBasicStatistics basicStatistics = statistics.getBasicStatistics();
            OptionalLong rowCount = basicStatistics.getRowCount();
            rowCount.ifPresent(count -> checkStatistics(count >= 0, table, partition, "rowCount must be greater than or equal to zero: %s", count));
            basicStatistics.getFileCount().ifPresent(count -> checkStatistics(count >= 0, table, partition, "fileCount must be greater than or equal to zero: %s", count));
            basicStatistics.getInMemoryDataSizeInBytes().ifPresent(size -> checkStatistics(size >= 0, table, partition, "inMemoryDataSizeInBytes must be greater than or equal to zero: %s", size));
            basicStatistics.getOnDiskDataSizeInBytes().ifPresent(size -> checkStatistics(size >= 0, table, partition, "onDiskDataSizeInBytes must be greater than or equal to zero: %s", size));
            statistics.getColumnStatistics().forEach((column, columnStatistics) -> validateColumnStatistics(table, partition, column, rowCount, columnStatistics));
        });
    }
@Test
    public void testValidatePartitionStatistics()
    {
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(-1, 0, 0, 0))
                        .build(),
                invalidPartitionStatistics("fileCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, -1, 0, 0))
                        .build(),
                invalidPartitionStatistics("rowCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, -1, 0))
                        .build(),
                invalidPartitionStatistics("inMemoryDataSizeInBytes must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, -1))
                        .build(),
                invalidPartitionStatistics("onDiskDataSizeInBytes must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setMaxValueSizeInBytes(-1).build()))
                        .build(),
                invalidColumnStatistics("maxValueSizeInBytes must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setTotalSizeInBytes(-1).build()))
                        .build(),
                invalidColumnStatistics("totalSizeInBytes must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setNullsCount(-1).build()))
                        .build(),
                invalidColumnStatistics("nullsCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setNullsCount(1).build()))
                        .build(),
                invalidColumnStatistics("nullsCount must be less than or equal to rowCount. nullsCount: 1. rowCount: 0."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setDistinctValuesCount(-1).build()))
                        .build(),
                invalidColumnStatistics("distinctValuesCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setDistinctValuesCount(1).build()))
                        .build(),
                invalidColumnStatistics("distinctValuesCount must be less than or equal to rowCount. distinctValuesCount: 1. rowCount: 0."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 1, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, HiveColumnStatistics.builder().setDistinctValuesCount(1).setNullsCount(1).build()))
                        .build(),
                invalidColumnStatistics("distinctValuesCount must be less than or equal to nonNullsCount. distinctValuesCount: 1. nonNullsCount: 0."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createIntegerColumnStatistics(OptionalLong.of(1), OptionalLong.of(-1), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("integerStatistics.min must be less than or equal to integerStatistics.max. integerStatistics.min: 1. integerStatistics.max: -1."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createDoubleColumnStatistics(OptionalDouble.of(1), OptionalDouble.of(-1), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("doubleStatistics.min must be less than or equal to doubleStatistics.max. doubleStatistics.min: 1.0. doubleStatistics.max: -1.0."));
        validatePartitionStatistics(
                TABLE,
                ImmutableMap.of(
                        PARTITION,
                        PartitionStatistics.builder()
                                .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                                .setColumnStatistics(ImmutableMap.of(COLUMN, createDoubleColumnStatistics(OptionalDouble.of(NaN), OptionalDouble.of(NaN), OptionalLong.empty(), OptionalLong.empty())))
                                .build()));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createDecimalColumnStatistics(Optional.of(BigDecimal.valueOf(1)), Optional.of(BigDecimal.valueOf(-1)), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("decimalStatistics.min must be less than or equal to decimalStatistics.max. decimalStatistics.min: 1. decimalStatistics.max: -1."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createDateColumnStatistics(Optional.of(LocalDate.ofEpochDay(1)), Optional.of(LocalDate.ofEpochDay(-1)), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("dateStatistics.min must be less than or equal to dateStatistics.max. dateStatistics.min: 1970-01-02. dateStatistics.max: 1969-12-31."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createBooleanColumnStatistics(OptionalLong.of(-1), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("trueCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createBooleanColumnStatistics(OptionalLong.empty(), OptionalLong.of(-1), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("falseCount must be greater than or equal to zero: -1"));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createBooleanColumnStatistics(OptionalLong.of(1), OptionalLong.empty(), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("booleanStatistics.trueCount must be less than or equal to rowCount. booleanStatistics.trueCount: 1. rowCount: 0."));
        assertInvalidStatistics(
                PartitionStatistics.builder()
                        .setBasicStatistics(new HiveBasicStatistics(0, 0, 0, 0))
                        .setColumnStatistics(ImmutableMap.of(COLUMN, createBooleanColumnStatistics(OptionalLong.empty(), OptionalLong.of(1), OptionalLong.empty())))
                        .build(),
                invalidColumnStatistics("booleanStatistics.falseCount must be less than or equal to rowCount. booleanStatistics.falseCount: 1. rowCount: 0."));
    }