yyanyy commented on a change in pull request #1641: URL: https://github.com/apache/iceberg/pull/1641#discussion_r513833966
########## File path: data/src/test/java/org/apache/iceberg/TestMergingMetrics.java ########## @@ -0,0 +1,166 @@ +/* + * 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 java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.iceberg.data.GenericRecord; +import org.apache.iceberg.data.RandomGenericData; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.io.FileAppender; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; +import org.apache.iceberg.types.Types; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.apache.iceberg.types.Types.NestedField.required; + +public abstract class TestMergingMetrics<T> { + + // all supported fields, except for UUID which is on deprecation path: see https://github.com/apache/iceberg/pull/1611 + // as well as Types.TimeType and Types.TimestampType.withoutZone as both are not supported by Spark + protected static final Types.NestedField ID_FIELD = required(1, "id", Types.IntegerType.get()); + protected static final Types.NestedField DATA_FIELD = optional(2, "data", Types.StringType.get()); + protected static final Types.NestedField FLOAT_FIELD = required(3, "float", Types.FloatType.get()); + protected static final Types.NestedField DOUBLE_FIELD = optional(4, "double", Types.DoubleType.get()); + protected static final Types.NestedField DECIMAL_FIELD = optional(5, "decimal", Types.DecimalType.of(5, 3)); + protected static final Types.NestedField FIXED_FIELD = optional(7, "fixed", Types.FixedType.ofLength(4)); + protected static final Types.NestedField BINARY_FIELD = optional(8, "binary", Types.BinaryType.get()); + protected static final Types.NestedField FLOAT_LIST = optional(9, "floatlist", + Types.ListType.ofRequired(10, Types.FloatType.get())); + protected static final Types.NestedField LONG_FIELD = optional(11, "long", Types.LongType.get()); + + protected static final Types.NestedField MAP_FIELD_1 = optional(17, "map1", + Types.MapType.ofOptional(18, 19, Types.FloatType.get(), Types.StringType.get()) + ); + protected static final Types.NestedField MAP_FIELD_2 = optional(20, "map2", + Types.MapType.ofOptional(21, 22, Types.IntegerType.get(), Types.DoubleType.get()) + ); + protected static final Types.NestedField STRUCT_FIELD = optional(23, "structField", Types.StructType.of( + required(24, "booleanField", Types.BooleanType.get()), + optional(25, "date", Types.DateType.get()), + optional(27, "timestamp", Types.TimestampType.withZone()) + )); + + private static final Set<Integer> IDS_WITH_ZERO_NAN_COUNT = ImmutableSet.of(1, 2, 5, 7, 8, 11, 24, 25, 27); + + private static final Map<Types.NestedField, Integer> FIELDS_WITH_NAN_COUNT_TO_ID = ImmutableMap.of( + FLOAT_FIELD, 3, DOUBLE_FIELD, 4, FLOAT_LIST, 10, MAP_FIELD_1, 18, MAP_FIELD_2, 22 + ); Review comment: I currently put it this way so that file types other than parquet could use it, however I've noticed that ORC reports metrics differently than parquet. I think ORC currently doesn't report anything for elements in list/map type, but report metrics for the list/map type themselves, which is completely opposite to what parquet does today. I think what parquet does is more useful, and wonder if people have opinion on if we want to record element metrics for ORC along with the new NaN counter. This is not a blocker for this specific pr, but the ORC implementation is on its way and I'd like to gather feedback sooner the better. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
