ayushtkn commented on code in PR #4897: URL: https://github.com/apache/hive/pull/4897#discussion_r1407276282
########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/actions/HiveIcebergDeleteOrphanFiles.java: ########## @@ -0,0 +1,232 @@ +/* + * 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.mr.hive.actions; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.LocatedFileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.iceberg.DataTask; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.HasTableOperations; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.MetadataTableUtils; +import org.apache.iceberg.ReachableFileUtil; +import org.apache.iceberg.Snapshot; +import org.apache.iceberg.StructLike; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableScan; +import org.apache.iceberg.actions.DeleteOrphanFiles; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.relocated.com.google.common.util.concurrent.MoreExecutors; +import org.apache.iceberg.util.Tasks; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.iceberg.MetadataTableType.ALL_ENTRIES; + +public class HiveIcebergDeleteOrphanFiles implements DeleteOrphanFiles { + + public static final String METADATA_FOLDER_NAME = "metadata"; + public static final String DATA_FOLDER_NAME = "data"; + private static final Logger LOG = LoggerFactory.getLogger(HiveIcebergDeleteOrphanFiles.class); + private String tableLocation; + private long olderThanTimestamp = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(3); + private Consumer<String> deleteFunc; + private ExecutorService deleteExecutorService = MoreExecutors.newDirectExecutorService(); + + private final Configuration conf; + private final Table table; + + public HiveIcebergDeleteOrphanFiles(Configuration conf, Table table) { + this.conf = conf; + this.table = table; + this.deleteFunc = file -> table.io().deleteFile(file); + this.tableLocation = table.location(); + } + + @Override + public HiveIcebergDeleteOrphanFiles location(String location) { + this.tableLocation = location; + return this; + } + + @Override + public HiveIcebergDeleteOrphanFiles olderThan(long newOlderThanTimestamp) { + this.olderThanTimestamp = newOlderThanTimestamp; + return this; + } + + // TODO: Implement later, if there is any use case. + @Override + public HiveIcebergDeleteOrphanFiles deleteWith(Consumer<String> newDeleteFunc) { + this.deleteFunc = newDeleteFunc; + return this; + } + + @Override + public HiveIcebergDeleteOrphanFiles executeDeleteWith(ExecutorService executorService) { + this.deleteExecutorService = executorService; + return this; + } + + @Override + public Result execute() { + LOG.info("Cleaning orphan files for {}", table.name()); + HiveIcebergDeleteOrphanFilesResult result = new HiveIcebergDeleteOrphanFilesResult(); + result.addDeletedFiles(cleanContentFiles(olderThanTimestamp)); + result.addDeletedFiles(cleanMetadata(olderThanTimestamp)); Review Comment: makes sense, I will create a ticket for that, thx -- 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]
