pvary commented on code in PR #13302: URL: https://github.com/apache/iceberg/pull/13302#discussion_r2166065793
########## flink/v2.0/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/ListFileSystemFiles.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.util.List; +import java.util.Map; +import java.util.function.Predicate; +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.common.functions.OpenContext; +import org.apache.flink.metrics.Counter; +import org.apache.flink.streaming.api.functions.ProcessFunction; +import org.apache.flink.util.Collector; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.PathFilter; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Table; +import org.apache.iceberg.actions.PartitionAwareHiddenPathFilter; +import org.apache.iceberg.flink.TableLoader; +import org.apache.iceberg.flink.maintenance.api.DeleteOrphanFiles; +import org.apache.iceberg.flink.maintenance.api.Trigger; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.FileInfo; +import org.apache.iceberg.io.SupportsPrefixOperations; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.util.FileSystemWalker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Recursively lists the files in the `location` directory. Hidden files, and files younger than the + * `minAgeMs` are omitted in the result. + */ +@Internal +public class ListFileSystemFiles extends ProcessFunction<Trigger, String> { + private static final Logger LOG = LoggerFactory.getLogger(ListFileSystemFiles.class); + + private final String taskName; + private final int taskIndex; + + private FileIO io; + private Map<Integer, PartitionSpec> specs; + private String location; + private final long minAgeMs; + private transient Counter errorCounter; + private final TableLoader tableLoader; + private final boolean usePrefixListing; + private transient Configuration configuration; + private final int maxListingDepth; + private final int maxListingDirectSubDirs; + + public ListFileSystemFiles( + String taskName, + int taskIndex, + TableLoader tableLoader, + String location, + long minAgeMs, + boolean usePrefixListing, + int maxListingDepth, + int maxListingDirectSubDirs) { + Preconditions.checkNotNull(taskName, "Task name should no be null"); + Preconditions.checkNotNull(tableLoader, "TableLoad should no be null"); + + this.tableLoader = tableLoader; + this.taskName = taskName; + this.taskIndex = taskIndex; + this.minAgeMs = minAgeMs; + this.location = location; + this.usePrefixListing = usePrefixListing; + this.maxListingDepth = maxListingDepth; + this.maxListingDirectSubDirs = maxListingDirectSubDirs; + } + + @Override + public void open(OpenContext openContext) throws Exception { + super.open(openContext); + tableLoader.open(); + Table table = tableLoader.loadTable(); + this.io = table.io(); + this.location = location != null ? location : table.location(); + this.specs = table.specs(); + this.errorCounter = + TableMaintenanceMetrics.groupFor(getRuntimeContext(), table.name(), taskName, taskIndex) + .counter(TableMaintenanceMetrics.ERROR_COUNTER); + this.configuration = new Configuration(); + table.properties().forEach(configuration::set); + } + + @Override + public void processElement(Trigger trigger, Context ctx, Collector<String> out) throws Exception { + long olderThanTimestamp = trigger.timestamp() - minAgeMs; + try { + PathFilter filter = PartitionAwareHiddenPathFilter.forSpecs(specs); Review Comment: I was wondering if we could push the `PartitionAwareHiddenPathFilter` to the `FileSystemWalker`, and don't expose it in public API -- 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