mxm commented on code in PR #15996: URL: https://github.com/apache/iceberg/pull/15996#discussion_r3225246513
########## flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/ReadCommand.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.flink.maintenance.operator; + +import java.io.Serializable; +import java.util.List; +import org.apache.flink.annotation.Internal; +import org.apache.iceberg.AddedRowsScanTask; +import org.apache.iceberg.ContentScanTask; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DeleteFile; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.PositionDeletesScanTask; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; + +/** + * Envelope from the {@link EqualityConvertPlanner} to the {@link EqualityConvertReader}, wrapping + * an Iceberg {@link ContentScanTask} plus the metadata the reader needs to process it. + * + * <p>Analogous to {@code FlinkInputSplit}, which wraps a {@code CombinedScanTask} along with its + * own split-level metadata. Here the envelope carries: + * + * <ul> + * <li>The underlying scan task: {@link AddedRowsScanTask} for data files, {@link ContentScanTask} + * <{@link DeleteFile}> for equality delete files, {@link PositionDeletesScanTask} for + * positional delete files. + * <li>{@code equalityFieldIds}: the PK columns the worker keys on. Needed for data files + * (projection) and equality delete files; unused for positional deletes. + * <li>{@code mainSnapshotId}: the worker's generation tag. When this changes between cycles the + * worker clears its keyed state (reindex). {@code null} is allowed and means the main branch + * has no snapshot yet. + * </ul> + */ +@Internal +public class ReadCommand implements Serializable { + + private final ContentScanTask<?> task; + private final List<Integer> equalityFieldIds; + // Can be null if the main branch does not contain any snapshots. + private final Long mainSnapshotId; + + private ReadCommand( + ContentScanTask<?> task, List<Integer> equalityFieldIds, Long mainSnapshotId) { + this.task = task; + this.equalityFieldIds = Lists.newArrayList(equalityFieldIds); + this.mainSnapshotId = mainSnapshotId; + } + + public static ReadCommand dataFile( + DataFile file, + PartitionSpec spec, + long commitSnapshotId, + List<Integer> equalityFieldIds, + Long mainSnapshotId) { + return dataFile( + file, spec, commitSnapshotId, equalityFieldIds, mainSnapshotId, Lists.newArrayList()); + } + + public static ReadCommand dataFile( + DataFile file, + PartitionSpec spec, + long commitSnapshotId, + List<Integer> equalityFieldIds, + Long mainSnapshotId, + List<DeleteFile> existingDeletes) { + return new ReadCommand( + new FlinkAddedRowsScanTask(file, spec, commitSnapshotId, existingDeletes), + equalityFieldIds, + mainSnapshotId); + } + + public static ReadCommand eqDeleteFile( + DeleteFile file, PartitionSpec spec, List<Integer> equalityFieldIds, Long mainSnapshotId) { + return new ReadCommand( + new EqualityDeleteFileScanTask(file, spec), equalityFieldIds, mainSnapshotId); Review Comment: The equality fields are now fixed, set at the builder. If we discover other fields, we will fail: https://github.com/apache/iceberg/blob/d68940a0c9a037c44bbaaced8689cdcab2569346/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/EqualityConvertPlanner.java#L438 -- 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]
