rdblue commented on code in PR #15854: URL: https://github.com/apache/iceberg/pull/15854#discussion_r3133396016
########## core/src/main/java/org/apache/iceberg/TrackingStruct.java: ########## @@ -0,0 +1,235 @@ +/* + * 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.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, Serializable { + 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, + MetadataColumns.ROW_POSITION); + + private EntryStatus status = null; + private Long snapshotId = null; + private Long dataSequenceNumber = 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 + private String manifestLocation = null; + private long manifestPos = -1L; + + TrackingStruct(Types.StructType type) { + super(BASE_TYPE, type); + } + + private TrackingStruct(TrackingStruct toCopy) { + super(toCopy); + this.status = toCopy.status; + this.snapshotId = toCopy.snapshotId; + this.dataSequenceNumber = toCopy.dataSequenceNumber; + 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; + this.manifestLocation = toCopy.manifestLocation; + this.manifestPos = toCopy.manifestPos; + } + + void inheritFrom(Tracking manifestTracking) { + if (manifestTracking != null) { + if (snapshotId == null) { + this.snapshotId = manifestTracking.snapshotId(); + } + + if (status == EntryStatus.ADDED) { + if (dataSequenceNumber == null) { + this.dataSequenceNumber = manifestTracking.dataSequenceNumber(); + } + + if (fileSequenceNumber == null) { + this.fileSequenceNumber = manifestTracking.dataSequenceNumber(); Review Comment: > Conceptually, it is like file sequence number. We can just call it `sequence_number` and explains in the spec that it is the sequence number of the snapshot where the manifest file is added? The problem with this is that we want a single unified schema for the root manifest. I don't think it is worth introducing another column for manifests, so I would inherit from `file_sequence_number`. However, I think Amogh's suggestion to set it in both places is right. Another concern is whether these fields are required or optional. In leaf manifests, they should be optional because the value is not known when the manifest is written and `null` triggers inheritance. However the root manifest is written for each attempt so the sequence number is known when it is written. The root should allow sequence numbers for data files to be `null`, so the field should be `required`. But because manifests use the same field, that means we need a value for data and file sequence numbers. So Amogh is right: we should store both and they must be equal to the current attempt's sequence number. The inheritance code here (using file seq) is correct. -- 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]
