singhpk234 commented on code in PR #17557: URL: https://github.com/apache/iceberg/pull/17557#discussion_r3758644268
########## parquet/src/test/java/org/apache/iceberg/parquet/TestParquetMissingNullCount.java: ########## @@ -0,0 +1,220 @@ +/* + * 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.parquet; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DataFiles; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.ManifestFiles; +import org.apache.iceberg.ManifestReader; +import org.apache.iceberg.ManifestWriter; +import org.apache.iceberg.Metrics; +import org.apache.iceberg.MetricsConfig; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.expressions.InclusiveMetricsEvaluator; +import org.apache.iceberg.inmemory.InMemoryFileIO; +import org.apache.iceberg.inmemory.InMemoryOutputFile; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.types.Types.IntegerType; +import org.apache.parquet.column.Encoding; +import org.apache.parquet.column.statistics.Statistics; +import org.apache.parquet.hadoop.metadata.BlockMetaData; +import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; +import org.apache.parquet.hadoop.metadata.ColumnPath; +import org.apache.parquet.hadoop.metadata.CompressionCodecName; +import org.apache.parquet.hadoop.metadata.FileMetaData; +import org.apache.parquet.hadoop.metadata.ParquetMetadata; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; +import org.apache.parquet.schema.Type; +import org.apache.parquet.schema.Types; +import org.junit.jupiter.api.Test; + +/** + * Tests metrics for files whose column chunk stats omit {@code null_count}, which is allowed by the + * format. Parquet reports a missing count as -1 from {@link Statistics#getNumNulls()}, so it must + * not be summed into a total. + */ +public class TestParquetMissingNullCount { + + private static final MessageType PARQUET_SCHEMA = + Types.buildMessage() + .addField( + Types.primitive(PrimitiveType.PrimitiveTypeName.INT32, Type.Repetition.OPTIONAL) + .id(1) + .named("id")) + .named("table"); + + private static final PrimitiveType ID_TYPE = PARQUET_SCHEMA.getType("id").asPrimitiveType(); + + private static final Schema SCHEMA = new Schema(optional(1, "id", IntegerType.get())); + private static final PartitionSpec SPEC = PartitionSpec.builderFor(SCHEMA).build(); + + @Test + public void testMissingNullCountInSingleRowGroup() { + Metrics metrics = metrics(block(statsWithoutNullCount(1, 10), 10)); + + assertThat(metrics.nullValueCounts()).doesNotContainKey(1); + assertThat(metrics.valueCounts()).containsEntry(1, 10L); + // a missing null count does not invalidate the bounds + assertThat(metrics.lowerBounds()).containsKey(1); + assertThat(metrics.upperBounds()).containsKey(1); + } + + @Test + public void testMissingNullCountInOneOfTwoRowGroups() { + // without accounting for the -1 sentinel, this sums to an incorrect null count of 0 + Metrics metrics = metrics(block(statsWithoutNullCount(1, 10), 10), block(stats(20, 30, 1), 10)); + + assertThat(metrics.nullValueCounts()).doesNotContainKey(1); Review Comment: should we instead assert what the val returned is ? -1 right ? ########## parquet/src/test/java/org/apache/iceberg/parquet/TestParquetMissingNullCount.java: ########## @@ -0,0 +1,220 @@ +/* + * 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.parquet; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DataFiles; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.ManifestFiles; +import org.apache.iceberg.ManifestReader; +import org.apache.iceberg.ManifestWriter; +import org.apache.iceberg.Metrics; +import org.apache.iceberg.MetricsConfig; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.expressions.InclusiveMetricsEvaluator; +import org.apache.iceberg.inmemory.InMemoryFileIO; +import org.apache.iceberg.inmemory.InMemoryOutputFile; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.types.Types.IntegerType; +import org.apache.parquet.column.Encoding; +import org.apache.parquet.column.statistics.Statistics; +import org.apache.parquet.hadoop.metadata.BlockMetaData; +import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; +import org.apache.parquet.hadoop.metadata.ColumnPath; +import org.apache.parquet.hadoop.metadata.CompressionCodecName; +import org.apache.parquet.hadoop.metadata.FileMetaData; +import org.apache.parquet.hadoop.metadata.ParquetMetadata; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; +import org.apache.parquet.schema.Type; +import org.apache.parquet.schema.Types; +import org.junit.jupiter.api.Test; + +/** + * Tests metrics for files whose column chunk stats omit {@code null_count}, which is allowed by the + * format. Parquet reports a missing count as -1 from {@link Statistics#getNumNulls()}, so it must + * not be summed into a total. + */ +public class TestParquetMissingNullCount { + + private static final MessageType PARQUET_SCHEMA = + Types.buildMessage() + .addField( + Types.primitive(PrimitiveType.PrimitiveTypeName.INT32, Type.Repetition.OPTIONAL) + .id(1) + .named("id")) + .named("table"); + + private static final PrimitiveType ID_TYPE = PARQUET_SCHEMA.getType("id").asPrimitiveType(); + + private static final Schema SCHEMA = new Schema(optional(1, "id", IntegerType.get())); + private static final PartitionSpec SPEC = PartitionSpec.builderFor(SCHEMA).build(); + + @Test + public void testMissingNullCountInSingleRowGroup() { Review Comment: let remove `test` prefix ... something we are trying to follow cross code base. -- 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]
