szehon-ho commented on code in PR #10920: URL: https://github.com/apache/iceberg/pull/10920#discussion_r1799850281
########## api/src/main/java/org/apache/iceberg/actions/RewriteTablePath.java: ########## @@ -0,0 +1,102 @@ +/* + * 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; + +/** + * An action that rewrites the table's metadata files to a staging directory, replacing all source + * prefixes in absolute paths with a specified target prefix. There are two modes: + * + * <ul> + * <li><b>Complete copy:</b> Rewrites all metadata files to the staging directory. + * <li><b>Incremental copy:</b> Rewrites a subset of metadata files to the staging directory, + * consisting of metadata files added since a specified start version and/or until end + * version. The start/end version is identified by the name of a metadata.json file, and all + * metadata files added before/after these file are marked for rewrite. + * </ul> + * + * This action can be used as the starting point to fully or incrementally copy an Iceberg table + * located under the source prefix to the target prefix. + * + * <p>The action returns the following: + * + * <ol> + * <li>The name of the latest metadata.json file copied. + * <li>A listing of rewritten table metadata files, relative to the staging directory, that can be + * copied to the target prefix. + * <li>A listing of table data files, relative to the source prefix, that can be copied to the + * target prefix. + * </ol> + */ +public interface RewriteTablePath extends Action<RewriteTablePath, RewriteTablePath.Result> { + + /** + * Configure a source prefix that will be replaced by the specified target prefix in all paths + * + * @param sourcePrefix the source prefix to be replaced + * @param targetPrefix the target prefix + * @return this for method chaining + */ + RewriteTablePath rewriteLocationPrefix(String sourcePrefix, String targetPrefix); + + /** + * First metadata version to rewrite, identified by name of a metadata.json file in the table's + * metadata log. It is optional, if provided then this action will only rewrite metadata files + * added after this version. + * + * @param startVersion name of a metadata.json file. For example, + * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". + * @return this for method chaining + */ + RewriteTablePath startVersion(String startVersion); + + /** + * Last metadata version to rewrite, identified by name of a metadata.json file in the table's + * metadata log. It is optional, if provided then this action will only rewrite metadata files + * added before this file, including the file itself. + * + * @param endVersion name of a metadata.json file. For example, + * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". + * @return this for method chaining + */ + RewriteTablePath endVersion(String endVersion); + + /** + * Custom staging location. It is optional. By default, staging location is a subdirectory under + * table's metadata directory. + * + * @param stagingLocation the staging location + * @return this for method chaining + */ + RewriteTablePath stagingLocation(String stagingLocation); + + /** The action result that contains a summary of the execution. */ + interface Result { + /** staging location of rewritten files */ + String stagingLocation(); + + /** + * path to a list of comma-separated pairs of source and target path for data and metadata Review Comment: How about: Path to a list of comma-separated pairs of source path to target path for all files in the table added between startVersion and endVersion. Note that this list includes data files from the original table and metadata files rewritten to staging. ########## api/src/main/java/org/apache/iceberg/actions/RewriteTablePath.java: ########## @@ -0,0 +1,91 @@ +/* + * 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 org.apache.iceberg.Table; + +public interface RewriteTablePath extends Action<RewriteTablePath, RewriteTablePath.Result> { + + /** + * Passes the source and target prefixes that will be used to replace the source prefix with the + * target one. + * + * @param sourcePrefix the source prefix to be replaced + * @param targetPrefix the target prefix + * @return this for method chaining + */ + RewriteTablePath rewriteLocationPrefix(String sourcePrefix, String targetPrefix); + + /** + * Pass the version copied last time. It is optional if the target table is provided. The default + * value is the target table's current version. User needs to make sure whether the start version + * is valid if target table is not provided. + * + * @param lastCopiedVersion only version file name is needed, not the metadata json file path. For + * example, the version file would be "v2.metadata.json" for a Hadoop table. For metastore + * tables, the version file would be like + * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". + * @return this for method chaining + */ + RewriteTablePath lastCopiedVersion(String lastCopiedVersion); + + /** + * The latest version of the table to copy. It is optional, the default value is the source + * table's current version. + * + * @param endVersion only version file name is needed, not the metadata json file path. For + * example, the version file would be "v2.metadata.json" for a Hadoop table. For metastore + * tables, the version file would be like + * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". + * @return this for method chaining + */ + RewriteTablePath endVersion(String endVersion); + + /** + * Set the customized staging location. It is optional. By default, staging location is a + * subdirectory under table's metadata directory. + * + * @param stagingLocation the staging location + * @return this for method chaining + */ + RewriteTablePath stagingLocation(String stagingLocation); + + /** + * Set the target table. It is optional if the start version is provided. + * + * @param targetTable the target table + * @return this for method chaining + */ + RewriteTablePath targetTable(Table targetTable); + + /** The action result that contains a summary of the execution. */ + interface Result { Review Comment: > Since deleteFiles already exists under the metadata folder in the storage I thought its generally not the case, and they co-exist with the data files in the partition folder. Hence my initial comment. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org