rdblue commented on code in PR #17322: URL: https://github.com/apache/iceberg/pull/17322#discussion_r3641597892
########## core/src/test/java/org/apache/iceberg/TestContentStatsBackedMap.java: ########## @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; + +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; +import org.apache.iceberg.types.Conversions; +import org.apache.iceberg.types.Types; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class TestContentStatsBackedMap { + private static final Schema SCHEMA = + new Schema( + required(1, "req", Types.LongType.get()), + optional(2, "opt", Types.LongType.get()), + optional(3, "dbl", Types.DoubleType.get())); + private static final Types.StructType STATS_TYPE = + StatsUtil.statsReadSchema(SCHEMA, List.of(1, 2, 3)); + + private static Types.StructType statsType(String name) { + return STATS_TYPE.field(name).type().asStructType(); + } + + private static final ContentStatsStruct POPULATED_STATS = new ContentStatsStruct(STATS_TYPE); + private static final ContentStatsStruct ONLY_REQUIRED_STATS = new ContentStatsStruct(STATS_TYPE); + + static { + POPULATED_STATS.setStats(1, mockFieldStats("req", 1, 1L, 5L, 10L, null, null)); + POPULATED_STATS.setStats(2, mockFieldStats("opt", 2, 2L, 6L, 20L, 3L, null)); + POPULATED_STATS.setStats(3, mockFieldStats("dbl", 3, 1.0, 9.0, 30L, 7L, 4L)); + + // only a required long column: tracks a value count but no null or NaN count + ONLY_REQUIRED_STATS.setStats(1, mockFieldStats("req", 1, 1L, 5L, 10L, null, null)); + } + + @Test + public void testValueCounts() { + Map<Integer, Long> map = ContentStatsBackedMap.valueCounts(POPULATED_STATS); + assertThat(map).containsOnly(Map.entry(1, 10L), Map.entry(2, 20L), Map.entry(3, 30L)); + } + + @Test + public void testNullValueCountsSkipsColumnsThatDoNotTrackIt() { + // required column 1 does not track null_value_count; only the optional columns do + Map<Integer, Long> map = ContentStatsBackedMap.nullValueCounts(POPULATED_STATS); + assertThat(map.get(1)).isNull(); + assertThat(map.containsKey(1)).isFalse(); + assertThat(map).containsOnly(Map.entry(2, 3L), Map.entry(3, 7L)); + } + + @Test + public void testGetDoesNotUnboxUntrackedNullCount() { Review Comment: This duplicates the null value count test above, just without the third entry for dbl. I think you can remove it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
