rdblue commented on a change in pull request #1060:
URL: https://github.com/apache/iceberg/pull/1060#discussion_r432796034



##########
File path: data/src/test/java/org/apache/iceberg/data/TestAppenderMetrics.java
##########
@@ -0,0 +1,300 @@
+/*
+ * 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.data;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.Metrics;
+import org.apache.iceberg.MetricsAppender;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.data.avro.DataWriter;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.types.Type;
+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.Conversions.fromByteBuffer;
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+/**
+ * TODO: build TestAvroMetrics similar to TestParquetMetrics.
+ */
+public class TestAppenderMetrics {

Review comment:
       Hm. Okay, the problem is that we may not pass the same types to the 
appender. The underlying format creates a writer tree based on the object model 
used. We have a few: Iceberg generics, Spark internal rows, and Avro records. 
It looks like the metrics code would need to be specific to the in-memory 
object model that is used, or would need to ignore types that have different 
representations, like fixed (byte[], ByteBuffer, GenericFixed), date (int, 
LocalDate), and timestamptz (long, OffsetDateTime).
   
   Another option is to embed the metrics logic from this PR into the writers. 
For example, Avro has a 
[LongWriter](https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/avro/ValueWriters.java#L197)
 that knows how to write a long value to an Avro file. That could also 
accumulate metrics. Then we could just return the metrics up the writer tree, 
instead of having a separate `MetricsCollector` tree. Then after writing a 
file, the `AvroFileAppender` could call `writer.getMetrics()` just like you 
currently have.
   
   I hope that helps!




----------------------------------------------------------------
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]

Reply via email to