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



##########
File path: core/src/main/java/org/apache/iceberg/avro/ValueWriters.java
##########
@@ -369,17 +393,42 @@ private OptionWriter(int nullIndex, ValueWriter<T> 
valueWriter) {
         throw new IllegalArgumentException("Invalid option index: " + 
nullIndex);
       }
       this.valueWriter = valueWriter;
+      this.type = type;
+      this.nullValueCount = 0;
     }
 
     @Override
     public void write(T option, Encoder encoder) throws IOException {
       if (option == null) {
         encoder.writeIndex(nullIndex);
+        nullValueCount++;
       } else {
         encoder.writeIndex(valueIndex);
         valueWriter.write(option, encoder);
       }
     }
+
+    @Override
+    public Stream<FieldMetrics> metrics() {
+      if (AvroSchemaUtil.isMetricSupportedType(type)) {
+        return mergeNullCountIntoMetric();
+      } else {
+        return valueWriter.metrics();
+      }
+    }
+
+    private Stream<FieldMetrics> mergeNullCountIntoMetric() {
+      List<FieldMetrics> fieldMetricsFromWriter = 
valueWriter.metrics().collect(Collectors.toList());
+      Preconditions.checkState(fieldMetricsFromWriter.size() == 1,
+          "Optional field for type % shouldn't vend more than one field 
metrics", type);

Review comment:
       Okay, thinking about this a bit more, I don't think this assumption 
holds.
   
   There are lots of times when a structure in the middle of a record might be 
optional. An optional map, for example, would have both key and value metrics. 
I think that we should only merge null in if we know that this is wrapping a 
leaf writer, not a map, list, or struct writer.




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