stevenzwu commented on code in PR #17322:
URL: https://github.com/apache/iceberg/pull/17322#discussion_r3634097525


##########
core/src/main/java/org/apache/iceberg/ContentStatsBackedMap.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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;
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Types;
+
+/**
+ * A lazy, read-only {@link Map} view of one stat across the columns of a 
{@link ContentStats},
+ * keyed by field ID, mirroring the per-column stat maps on {@link 
ContentFile}.
+ */
+class ContentStatsBackedMap<V> extends AbstractMap<Integer, V> {
+  enum Kind {
+    VALUE_COUNT,
+    NULL_VALUE_COUNT,
+    NAN_VALUE_COUNT,
+    LOWER_BOUND,
+    UPPER_BOUND
+  }
+
+  private final ContentStats stats;
+  private final Kind kind;
+  private Map<Integer, V> materialized;
+
+  ContentStatsBackedMap(ContentStats stats, Kind kind) {
+    this.stats = stats;
+    this.kind = kind;
+  }
+
+  /** Returns a lazy view of the metric across columns, or {@code null} if no 
column tracks it. */
+  static <V> Map<Integer, V> forKind(Kind kind, ContentStats stats) {
+    return isEmpty(stats, kind) ? null : new ContentStatsBackedMap<>(stats, 
kind);

Review Comment:
   `isEmpty` check adds some overhead as it needs to iterates through the 
`FieldStats` collection in the `ContentStats`. But I think it is worth to have 
this for two reason.
   
   1. The `ContentFile` interface states null map if not collected.
   ```
     /** Returns if collected, map from column ID to its null value count, null 
otherwise. */
     Map<Integer, Long> nullValueCounts();
   ```
   
   2. `isEmpty` short-circuit and return early if it detects a `FieldStats` has 
stats for the kind. In most production scenarios, I imagine short-circuit 
should kick in.



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