rdblue commented on code in PR #17159: URL: https://github.com/apache/iceberg/pull/17159#discussion_r3589949471
########## core/src/main/java/org/apache/iceberg/FieldStatsStruct.java: ########## @@ -0,0 +1,220 @@ +/* + * 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.io.Serializable; +import java.nio.ByteBuffer; +import java.util.List; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; +import org.apache.iceberg.util.ByteBuffers; + +class FieldStatsStruct<T> implements FieldStats<T>, StructLike, Serializable { + private final Types.StructType struct; + private final Type boundType; + private final int[] posToOffset; + private final int fieldId; + + private Object lowerBound = null; + private Object upperBound = null; + private boolean tightBounds = false; + private Long valueCount = null; + private Long nullValueCount = null; + private Long nanValueCount = null; + private Integer avgValueSize = null; + + FieldStatsStruct(Types.StructType struct) { + this.struct = struct; + this.posToOffset = posToOffset(struct); + this.fieldId = StatsUtil.toFieldId(struct.fields().get(0).fieldId()); + this.boundType = struct.fieldType("lower_bound"); + } + + FieldStatsStruct( + Types.StructType struct, + T lowerBound, + T upperBound, + boolean tightBounds, + long valueCount, + long nullValueCount, + long nanValueCount, + Integer avgValueSize) { + this(struct); + setLowerBound(lowerBound); + setUpperBound(upperBound); + this.tightBounds = tightBounds; + this.valueCount = valueCount; + this.nullValueCount = nullValueCount; + this.nanValueCount = nanValueCount; + this.avgValueSize = avgValueSize; + } + + private FieldStatsStruct(FieldStatsStruct<T> toCopy) { + this(toCopy.struct); + // bounds are stored using the internal representation, which is a byte array for binary types + this.lowerBound = + toCopy.lowerBound instanceof byte[] + ? ((byte[]) toCopy.lowerBound).clone() + : toCopy.lowerBound; + this.upperBound = + toCopy.upperBound instanceof byte[] + ? ((byte[]) toCopy.upperBound).clone() + : toCopy.upperBound; + this.tightBounds = toCopy.tightBounds; + this.valueCount = toCopy.valueCount; + this.nullValueCount = toCopy.nullValueCount; + this.nanValueCount = toCopy.nanValueCount; + this.avgValueSize = toCopy.avgValueSize; + } + + void fromFieldMetrics(FieldMetrics<T> fieldMetrics) { + Preconditions.checkArgument( + fieldMetrics.id() == fieldId, + "Cannot store stats for field ID: %s (expected %s)", + fieldMetrics.id(), + fieldId); + + setLowerBound(fieldMetrics.lowerBound()); + setUpperBound(fieldMetrics.upperBound()); + this.tightBounds = false; + this.valueCount = fieldMetrics.valueCount(); + this.nullValueCount = fieldMetrics.nullValueCount() < 0 ? null : fieldMetrics.nullValueCount(); Review Comment: `null` means unknown internally, so it is correct. Then the question is how we expose that unknown state to the caller. There's a thread with Amogh about this on the interface. The short answer is that I think we should introduce a method like `hasNullValueCount` to handle this rather than making `nullValueCount` return null values. -- 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]
