huaxingao commented on code in PR #15727: URL: https://github.com/apache/iceberg/pull/15727#discussion_r3918711955
########## core/src/main/java/org/apache/iceberg/actions/RemoveDanglingDeleteFilesAction.java: ########## @@ -0,0 +1,141 @@ +/* + * 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.actions; + +import java.io.IOException; +import java.util.List; +import org.apache.iceberg.DeleteFile; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.ManifestFiles; +import org.apache.iceberg.ManifestReader; +import org.apache.iceberg.RewriteFiles; +import org.apache.iceberg.Snapshot; +import org.apache.iceberg.SnapshotRef; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableScan; +import org.apache.iceberg.exceptions.RuntimeIOException; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.util.DeleteFileSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RemoveDanglingDeleteFilesAction + extends BaseSnapshotUpdateAction<RemoveDanglingDeleteFiles, RemoveDanglingDeleteFiles.Result> + implements RemoveDanglingDeleteFiles { + + private static final Logger LOG = LoggerFactory.getLogger(RemoveDanglingDeleteFilesAction.class); + private static final List<String> DELETE_COLUMNS = + ImmutableList.of("file_path", "content_offset", "content_size_in_bytes"); + + private final Table table; + private String branch = SnapshotRef.MAIN_BRANCH; + private Snapshot snapshot; + + public RemoveDanglingDeleteFilesAction(Table table) { + this.table = table; + } + + @Override + protected RemoveDanglingDeleteFilesAction self() { + return this; + } + + @Override + public Table table() { + return table; + } + + public RemoveDanglingDeleteFilesAction toBranch(String targetBranch) { + Preconditions.checkArgument(targetBranch != null, "Invalid branch name: null"); + this.branch = targetBranch; + return this; + } + + public RemoveDanglingDeleteFilesAction init() { Review Comment: I'd drop `init()` and resolve the snapshot as a local in `execute()`. As a public method it makes the result depend on the order the caller makes its calls, and nothing guards against getting that order wrong. Since `execute()` only calls `init()` when `snapshot` is null, `action.init().toBranch("x").execute()` resolves the snapshot while `branch` is still `main`, then commits that decision to `x`. The only callers are the three Spark wrappers, and there `init()` only makes the "branch does not exist" check run slightly earlier, so this should be free to change. -- 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]
