rdblue commented on code in PR #15854: URL: https://github.com/apache/iceberg/pull/15854#discussion_r3082516780
########## core/src/main/java/org/apache/iceberg/TrackingStruct.java: ########## @@ -0,0 +1,209 @@ +/* + * 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.Arrays; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; +import org.apache.iceberg.types.Types; +import org.apache.iceberg.util.ByteBuffers; + +/** Mutable {@link StructLike} implementation of {@link Tracking}. */ +class TrackingStruct implements Tracking, StructLike, Serializable { + private static final EntryStatus[] STATUS_VALUES = EntryStatus.values(); + + private EntryStatus status = EntryStatus.EXISTING; + private Long snapshotId = null; + private Long sequenceNumber = null; + private Long fileSequenceNumber = null; + private Long dvSnapshotId = null; + private Long firstRowId = null; + private byte[] deletedPositions = null; + private byte[] replacedPositions = null; + + // not serialized, set by manifest readers for metadata inheritance + private transient TrackedFile manifestContext = null; + + TrackingStruct(Types.StructType type) {} + + private TrackingStruct(TrackingStruct toCopy) { + this.status = toCopy.status; + this.snapshotId = toCopy.snapshotId; + this.sequenceNumber = toCopy.sequenceNumber; + this.fileSequenceNumber = toCopy.fileSequenceNumber; + this.dvSnapshotId = toCopy.dvSnapshotId; + this.firstRowId = toCopy.firstRowId; + this.deletedPositions = + toCopy.deletedPositions != null + ? Arrays.copyOf(toCopy.deletedPositions, toCopy.deletedPositions.length) + : null; + this.replacedPositions = + toCopy.replacedPositions != null + ? Arrays.copyOf(toCopy.replacedPositions, toCopy.replacedPositions.length) + : null; + } + + TrackingStruct copy() { + return new TrackingStruct(this); + } + + void setManifestContext(TrackedFile manifest) { + this.manifestContext = manifest; + } + + @Override + public EntryStatus status() { + return status; + } + + @Override + public Long snapshotId() { + if (snapshotId != null) { + return snapshotId; + } + + return manifestContext != null ? manifestContext.tracking().snapshotId() : null; + } + + @Override + public Long dataSequenceNumber() { + if (sequenceNumber != null) { + return sequenceNumber; + } + + if (manifestContext != null && status == EntryStatus.ADDED) { + return manifestContext.tracking().dataSequenceNumber(); + } + + return null; + } + + @Override + public Long fileSequenceNumber() { + if (fileSequenceNumber != null) { + return fileSequenceNumber; + } + + if (manifestContext != null && status == EntryStatus.ADDED) { + return manifestContext.tracking().dataSequenceNumber(); + } + + return null; + } + + @Override + public Long dvSnapshotId() { + return dvSnapshotId; + } + + @Override + public Long firstRowId() { + return firstRowId; + } + + @Override + public ByteBuffer deletedPositions() { + return deletedPositions != null ? ByteBuffer.wrap(deletedPositions) : null; + } + + @Override + public ByteBuffer replacedPositions() { + return replacedPositions != null ? ByteBuffer.wrap(replacedPositions) : null; + } + + @Override + public int size() { + return 8; + } + + @Override + public <T> T get(int pos, Class<T> javaClass) { + return javaClass.cast(getByPos(pos)); + } + + private Object getByPos(int pos) { + switch (pos) { + case 0: + return status.id(); + case 1: + return snapshotId; Review Comment: This should return `snapshotId()` rather than the field so that inherited values are always explicitly carried forward. An alternative is to copy the data from `TrackedFile` to this one when `setManifestContext` is called. That's arguably cleaner, but I don't have a strong opinion right now. The most important thing is that this class never returns a `null` snapshot ID or other inherited metadata, either through a getter or through this method. -- 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]
