pvary commented on code in PR #15251:
URL: https://github.com/apache/iceberg/pull/15251#discussion_r2774924770


##########
core/src/main/java/org/apache/iceberg/MetricsUtil.java:
##########
@@ -476,4 +479,99 @@ public <T> void set(int pos, T value) {
       throw new UnsupportedOperationException("StructWithReadableMetrics is 
read only");
     }
   }
+
+  public static ContentStats fromMetrics(Schema schema, Metrics metrics) {
+    if (null == metrics) {
+      return null;
+    }
+
+    BaseContentStats.Builder builder = 
BaseContentStats.builder().withTableSchema(schema);
+    Map<Integer, BaseFieldStats<?>> map = Maps.newHashMap();
+
+    if (null != metrics.valueCounts()) {

Review Comment:
   What about:
   ```
     private static void mergeCountMetric(
         Map<Integer, BaseFieldStats<?>> map,
         Map<Integer, Long> counts,
         BiFunction<BaseFieldStats.Builder<Object>, Long, 
BaseFieldStats.Builder<Object>> setter) {
       if (counts == null) {
         return;
       }
   
       counts.forEach(
           (id, value) ->
               map.merge(
                   id,
                   setter.apply(BaseFieldStats.builder().fieldId(id), 
value).build(),
                   (oldVal, newVal) -> 
setter.apply(BaseFieldStats.buildFrom((BaseFieldStats<Object>) oldVal), 
value).build()));
     }
   
     private static void mergeBoundMetric(
         Map<Integer, BaseFieldStats<?>> map,
         Map<Integer, java.nio.ByteBuffer> bounds,
         Map<Integer, Type> originalTypes,
         BiFunction<BaseFieldStats.Builder<Object>, Object, 
BaseFieldStats.Builder<Object>> setter) {
       if (bounds == null || originalTypes == null) {
         return;
       }
   
       bounds.entrySet().stream()
           .filter(entry -> originalTypes.get(entry.getKey()) != null)
           .forEach(
               entry -> {
                 Integer id = entry.getKey();
                 Type type = originalTypes.get(id);
                 Object boundValue = Conversions.fromByteBuffer(type, 
entry.getValue());
                 map.merge(
                     id,
                     
setter.apply(BaseFieldStats.builder().fieldId(id).type(type), 
boundValue).build(),
                     (oldVal, newVal) ->
                         
setter.apply(BaseFieldStats.buildFrom((BaseFieldStats<Object>) 
oldVal).type(type), boundValue).build());
               });
     }
   ```



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

To unsubscribe, e-mail: [email protected]

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