yyanyy commented on a change in pull request #1790: URL: https://github.com/apache/iceberg/pull/1790#discussion_r528916952
########## File path: core/src/main/java/org/apache/iceberg/MetricsUtil.java ########## @@ -0,0 +1,46 @@ +/* + * 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.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; + +public class MetricsUtil { + + private MetricsUtil() { + } + + public static Map<Integer, Long> getNanValueCounts( + Stream<FieldMetrics> fieldMetrics, MetricsConfig metricsConfig, Schema inputSchema) { + if (fieldMetrics == null || inputSchema == null) { + return Maps.newHashMap(); + } + + return fieldMetrics + .filter(metrics -> { Review comment: Sure, I'll break this down ########## File path: api/src/main/java/org/apache/iceberg/NaNOnlyFieldMetrics.java ########## @@ -17,51 +17,50 @@ * under the License. */ -package org.apache.iceberg.parquet; +package org.apache.iceberg; import java.nio.ByteBuffer; -import org.apache.iceberg.FieldMetrics; /** - * Iceberg internally tracked field level metrics, used by Parquet writer only. + * Iceberg internally tracked field level metrics, used by Parquet and ORC writers only. * <p> - * Parquet keeps track of most metrics in its footer, and only NaN counter is actually tracked by writers. - * This wrapper ensures that metrics not being updated by Parquet writers will not be incorrectly used, by throwing + * Parquet/ORC keeps track of most metrics in file statistics, and only NaN counter is actually tracked by writers. + * This wrapper ensures that metrics not being updated by those writers will not be incorrectly used, by throwing * exceptions when they are accessed. */ -public class ParquetFieldMetrics extends FieldMetrics { Review comment: It's actually to allow Parquet and ORC to diverge from Avro, so we will use the actual `FiledMetrics` in avro ########## File path: flink/src/main/java/org/apache/iceberg/flink/data/FlinkOrcWriter.java ########## @@ -46,8 +50,8 @@ private FlinkOrcWriter(RowType rowType, Schema iSchema) { } } - public static OrcRowWriter<RowData> buildWriter(RowType rowType, Schema iSchema) { - return new FlinkOrcWriter(rowType, iSchema); + public static OrcRowWriter<RowData> buildWriter(RowType rowType, Schema iSchema, TypeDescription schema) { Review comment: Yeah I tried to avoid changing the signature but wasn't able to find id information from schema, I'll see if people more familiar with the project would have comment on this ########## File path: spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java ########## @@ -115,12 +120,30 @@ public short getShort(int ordinal) { @Override public int getInt(int ordinal) { - return struct.get(ordinal, Integer.class); + Object integer = struct.get(ordinal, Object.class); Review comment: This is needed for `TestMergingMetrics` to work for ORC (also mentioned in pr description) so I think it makes more sense to have this in here ########## File path: core/src/main/java/org/apache/iceberg/MetricsUtil.java ########## @@ -0,0 +1,46 @@ +/* + * 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.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; + +public class MetricsUtil { + + private MetricsUtil() { + } + + public static Map<Integer, Long> getNanValueCounts( Review comment: I was aware of that, but couldn't come up with a good name without `get` in this case (things like `generateCount`/`createCount` is longer and sounds like just for workaround the word "get"), and later assume it was fine since it's not an ordinary getter... Do you have a recommendation? ########## File path: data/src/main/java/org/apache/iceberg/data/orc/GenericOrcWriter.java ########## @@ -109,6 +112,10 @@ private WriteBuilder() { iPrimitive, primitive)); } } + + private int getFieldId(TypeDescription typeDescription) { Review comment: I personally think it's easier to read by segregating the abstract logic of what's doing here from the actual underlying implementation so I created the helper; do you feel strong about this? I'll see if other people have the same comment? ---------------------------------------------------------------- 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]
