rdblue commented on code in PR #15854: URL: https://github.com/apache/iceberg/pull/15854#discussion_r3103747351
########## core/src/main/java/org/apache/iceberg/TrackingStruct.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.Arrays; +import org.apache.iceberg.avro.SupportsIndexProjection; +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 extends SupportsIndexProjection implements Tracking { + private static final Types.StructType BASE_TYPE = + Types.StructType.of( + Tracking.STATUS, + Tracking.SNAPSHOT_ID, + Tracking.SEQUENCE_NUMBER, + Tracking.FILE_SEQUENCE_NUMBER, + Tracking.DV_SNAPSHOT_ID, + Tracking.FIRST_ROW_ID, + Tracking.DELETED_POSITIONS, + Tracking.REPLACED_POSITIONS); + + private EntryStatus status = null; + 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) { + super(BASE_TYPE, type); + } + + private TrackingStruct(TrackingStruct toCopy) { + super(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 + protected <T> T internalGet(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(); + case 2: + return dataSequenceNumber(); Review Comment: @stevenzwu that's the intent. When writing out tracking information, any inherited values should be explicitly written so that they don't change. The existing mechanism for v1-3 actually sets the values directly in the manifest entry object. Having support here (or in the reader) is a bit cleaner than having a separate inheritance object, but the behavior is the same. -- 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]
