You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/10/30 07:59:18 UTC

[GitHub] [iceberg] jackye1995 commented on a change in pull request #1641: Add NaN counter to Metrics and implement in Parquet writers

jackye1995 commented on a change in pull request #1641:
URL: https://github.com/apache/iceberg/pull/1641#discussion_r514915462



##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetUtil.java
##########
@@ -149,9 +149,25 @@ public static Metrics footerMetrics(ParquetMetadata metadata, MetricsConfig metr
     }
 
     return new Metrics(rowCount, columnSizes, valueCounts, nullValueCounts,
+        getNanValueCounts(fieldMetrics, metricsConfig, inputSchema),
         toBufferMap(fileSchema, lowerBounds), toBufferMap(fileSchema, upperBounds));
   }
 
+  private static Map<Integer, Long> getNanValueCounts(
+      Stream<FieldMetrics> fieldMetrics, MetricsConfig metricsConfig, Schema inputSchema) {
+    if (fieldMetrics == null || inputSchema == null) {
+      return Maps.newHashMap();
+    }
+
+    return fieldMetrics
+        .filter(metrics -> {
+          String alias = inputSchema.idToAlias(metrics.getId());
+          MetricsMode metricsMode = metricsConfig.columnMode(alias);
+          return metricsMode != MetricsModes.None.get();

Review comment:
       Based on the behavior of footer metrics, it is not clear to me if we should have this metrics for `Counts` mode.

##########
File path: api/src/main/java/org/apache/iceberg/FieldMetrics.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.nio.ByteBuffer;
+
+/**
+ * Iceberg internally tracked field level metrics.
+ */
+public class FieldMetrics {
+  private final int id;
+  private final long valueCount;

Review comment:
       Do we need all these metrics that can be obtained from the footer? To me it feels more reasonable for this class to only contain metrics that is not covered by the footer metrics.

##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueWriters.java
##########
@@ -137,11 +141,20 @@ public void write(int repetitionLevel, T value) {
     public void setColumnStore(ColumnWriteStore columnStore) {
       this.column.setColumnStore(columnStore);
     }
+
+    @Override
+    public Stream<FieldMetrics> metrics() {
+      if (id != null) {
+        return Stream.of(new FieldMetrics(id.intValue(), 0L, 0L, 0L, null, null));

Review comment:
       Yeah it's a messy change, it would be great if we can somehow not pass in the `id`

##########
File path: spark/src/main/java/org/apache/iceberg/spark/data/SparkParquetWriters.java
##########
@@ -126,38 +126,39 @@ private SparkParquetWriters() {
     @Override
     public ParquetValueWriter<?> primitive(DataType sType, PrimitiveType primitive) {
       ColumnDescriptor desc = type.getColumnDescription(currentPath());
+      Type.ID id = primitive.getId();

Review comment:
       I think it would be more clear with more documentation for the `FieldMetrics` class and the `Stream<FieldMetrics> metrics()` method.

##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetUtil.java
##########
@@ -65,28 +68,25 @@
   private ParquetUtil() {
   }
 
-  // Access modifier is package-private, to only allow use from existing tests
-  static Metrics fileMetrics(InputFile file) {
-    return fileMetrics(file, MetricsConfig.getDefault());
-  }
-
   public static Metrics fileMetrics(InputFile file, MetricsConfig metricsConfig) {
     return fileMetrics(file, metricsConfig, null);
   }
 
   public static Metrics fileMetrics(InputFile file, MetricsConfig metricsConfig, NameMapping nameMapping) {
     try (ParquetFileReader reader = ParquetFileReader.open(ParquetIO.file(file))) {
-      return footerMetrics(reader.getFooter(), metricsConfig, nameMapping);
+      return footerMetrics(reader.getFooter(), Stream.empty(), null, metricsConfig, nameMapping);
     } catch (IOException e) {
       throw new RuntimeIOException(e, "Failed to read footer of file: %s", file);
     }
   }
 
-  public static Metrics footerMetrics(ParquetMetadata metadata, MetricsConfig metricsConfig) {
-    return footerMetrics(metadata, metricsConfig, null);
+  public static Metrics footerMetrics(ParquetMetadata metadata, Stream<FieldMetrics> fieldMetrics,
+                                      Schema inputSchema, MetricsConfig metricsConfig) {
+    return footerMetrics(metadata, fieldMetrics, inputSchema, metricsConfig, null);
   }
 
-  public static Metrics footerMetrics(ParquetMetadata metadata, MetricsConfig metricsConfig, NameMapping nameMapping) {
+  public static Metrics footerMetrics(ParquetMetadata metadata, Stream<FieldMetrics> fieldMetrics,

Review comment:
       Why we want to change the interface to include `inputSchema`? Line 99-100 below already creates the `fieldSchema`, are they different?

##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetWriter.java
##########
@@ -121,7 +123,7 @@ public void add(T value) {
 
   @Override
   public Metrics metrics() {
-    return ParquetUtil.footerMetrics(writer.getFooter(), metricsConfig);
+    return ParquetUtil.footerMetrics(writer.getFooter(), model.metrics(), inputSchema, metricsConfig);

Review comment:
       Yeah, as my comment in the `ParquetUtil` class, we should investigate if they are actually the same schema.

##########
File path: parquet/src/main/java/org/apache/iceberg/parquet/ParquetValueWriter.java
##########
@@ -28,4 +30,7 @@
   List<TripleWriter<?>> columns();
 
   void setColumnStore(ColumnWriteStore columnStore);
+
+  Stream<FieldMetrics> metrics();

Review comment:
       Documentation needed. And is the name a bit too generic?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org