rdblue commented on code in PR #16936:
URL: https://github.com/apache/iceberg/pull/16936#discussion_r4170058959


##########
core/src/main/java/org/apache/iceberg/MapBackedContentStats.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+
+/** Reusable {@link ContentStats} view over a legacy {@link ContentFile}'s 
stat maps. */
+class MapBackedContentStats implements ContentStats, StructLike {
+  private final Types.StructType struct;
+  private final int[] posToId;
+  private final Map<Integer, FieldStats<?>> statsById;
+
+  private Map<Integer, Long> valueCounts;
+  private Map<Integer, Long> nullValueCounts;
+  private Map<Integer, Long> nanValueCounts;
+  private Map<Integer, ByteBuffer> lowerBounds;
+  private Map<Integer, ByteBuffer> upperBounds;
+
+  MapBackedContentStats(Types.StructType contentStatsType) {
+    Preconditions.checkArgument(contentStatsType != null, "Invalid content 
stats type: null");
+    this.struct = contentStatsType;
+    List<Types.NestedField> fields = struct.fields();
+    this.posToId = new int[fields.size()];
+    this.statsById = Maps.newHashMapWithExpectedSize(fields.size());
+    for (int i = 0; i < fields.size(); i += 1) {
+      Types.NestedField field = fields.get(i);
+      int fieldId = StatsUtil.toFieldId(field.fieldId());
+      Types.StructType fieldStatsType = field.type().asStructType();
+      posToId[i] = fieldId;
+      statsById.put(
+          fieldId, new MapBackedFieldStats<>(fieldStatsType, fieldId, 
boundType(fieldStatsType)));
+    }
+  }
+
+  MapBackedContentStats wrap(ContentFile<?> file) {
+    this.valueCounts = file.valueCounts();
+    this.nullValueCounts = file.nullValueCounts();
+    this.nanValueCounts = file.nanValueCounts();
+    this.lowerBounds = file.lowerBounds();
+    this.upperBounds = file.upperBounds();
+    return this;
+  }
+
+  private boolean hasStats(int id) {

Review Comment:
   I can't say I understand what was benchmarked, but fair enough. It should be 
fine.



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