huaxingao commented on code in PR #17322:
URL: https://github.com/apache/iceberg/pull/17322#discussion_r3625968751
##########
core/src/main/java/org/apache/iceberg/FieldStats.java:
##########
@@ -46,10 +46,16 @@ interface FieldStats<T> {
/** The total value count, including null and NaN */
long valueCount();
- /** The total null value count */
+ /** Whether a null value count is tracked for this field. */
+ boolean hasNullCount();
Review Comment:
Small naming nit: could we align these with the existing getters? They are
`nullValueCount()` and `nanValueCount()`, so `hasNullValueCount()` and
`hasNanValueCount()` would match,
##########
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) {
Review Comment:
Nit: the argument order here is `(kind, stats)`, but the constructor above
is `(stats, kind)` and the `static isEmpty` below is also `(stats, kind)`.
Could we make `forKind` match so the order is consistent across all three?
##########
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);
+ }
+
+ @Override
+ public V get(Object key) {
+ if (!(key instanceof Integer)) {
+ throw new ClassCastException("Key must be an Integer field id: " + key);
Review Comment:
This seems to be a behavior change from the `HashMap`s this replaces, which
returned `null` from `get` and `false` from `containsKey` for a missing or
wrong-typed key. Is this change intentional? If so, a short comment would help.
--
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]