aokolnychyi commented on a change in pull request #2564:
URL: https://github.com/apache/iceberg/pull/2564#discussion_r632662150



##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {

Review comment:
       I actually liked passing `Table` objects in the initial implementation 
as `TableOperations` is a very low-level API that is subject to change/be 
replaced. We are trying to avoid exposing it too much. I've refactored a few 
places in actions to work with `Table` and I think the only remaining part is 
getting all reachable files. It may be a good time to refactor the remaining 
parts in the actions that rely on `TableOperations`.

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file

Review comment:
       nit: It is not `version.txt`, so we should either say `of the version 
hint file` or `of the version-hint.text file`. 

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,

Review comment:
       nit: `metaFiles` -> `metadataFileLocations`

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,
+                                            FileIO io, boolean recursive) {
+    List<TableMetadata.MetadataLogEntry> metadataLogEntries = 
metadata.previousFiles();
+    if (metadataLogEntries.size() > 0) {
+      for (TableMetadata.MetadataLogEntry metadataLogEntry : 
metadataLogEntries) {
+        metaFiles.add(metadataLogEntry.file());
+      }
+      if (recursive) {
+        String metadataFileLocation = metadataLogEntries.get(0).file();
+        try {
+          TableMetadata newMetadata = TableMetadataParser.read(io, 
metadataFileLocation);

Review comment:
       nit: `newMetadata` -> `previousMetadata` or something?

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,
+                                            FileIO io, boolean recursive) {
+    List<TableMetadata.MetadataLogEntry> metadataLogEntries = 
metadata.previousFiles();
+    if (metadataLogEntries.size() > 0) {
+      for (TableMetadata.MetadataLogEntry metadataLogEntry : 
metadataLogEntries) {
+        metaFiles.add(metadataLogEntry.file());
+      }
+      if (recursive) {
+        String metadataFileLocation = metadataLogEntries.get(0).file();
+        try {
+          TableMetadata newMetadata = TableMetadataParser.read(io, 
metadataFileLocation);
+          metadataFileLocations(newMetadata, metaFiles, io, recursive);
+        } catch (Exception e) {
+          LOG.error("Failed to load {}", metadataFileLocation, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Returns locations of manifest lists in a table.
+   *
+   * @param table table for which manifestList needs to be fetched
+   * @return the paths of the Manifest Lists

Review comment:
       nit: `@return locations of manifest lists`

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved

Review comment:
       nit: same here

##########
File path: core/src/main/java/org/apache/iceberg/hadoop/Util.java
##########
@@ -38,6 +38,9 @@
 import org.slf4j.LoggerFactory;
 
 public class Util {
+
+  public static final String VERSION_HINT_TXT_FILENAME = "version-hint.text";

Review comment:
       +1 for creating a constant.
   
   I think we can drop `TXT` in the constant name, `VERSION_HINT_FILENAME` 
should be descriptive enough.

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,
+                                            FileIO io, boolean recursive) {
+    List<TableMetadata.MetadataLogEntry> metadataLogEntries = 
metadata.previousFiles();
+    if (metadataLogEntries.size() > 0) {
+      for (TableMetadata.MetadataLogEntry metadataLogEntry : 
metadataLogEntries) {
+        metaFiles.add(metadataLogEntry.file());
+      }
+      if (recursive) {
+        String metadataFileLocation = metadataLogEntries.get(0).file();

Review comment:
       Would it make sense to name it like `oldestMetadataFileLocation` or 
`previousMetadataFileLocation`?

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,
+                                            FileIO io, boolean recursive) {
+    List<TableMetadata.MetadataLogEntry> metadataLogEntries = 
metadata.previousFiles();
+    if (metadataLogEntries.size() > 0) {
+      for (TableMetadata.MetadataLogEntry metadataLogEntry : 
metadataLogEntries) {

Review comment:
       Can we add an import for `MetadataLogEntry` to shorten the lines?

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.

Review comment:
       nit: can we align both `when`?

##########
File path: core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.hadoop.Util;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReachableFileUtil {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+
+  private ReachableFileUtil() {
+  }
+
+  /**
+   * Returns the location of the version.text file
+   *
+   * @param ops tableOperation for which version.text path needs to be 
retrieved
+   * @return the location of the version hint file
+   */
+  public static String versionHintLocation(TableOperations ops) {
+    return ops.metadataFileLocation(Util.VERSION_HINT_TXT_FILENAME);
+  }
+
+  /**
+   * Returns locations of JSON metadata files in a table.
+   *
+   * @param ops       TableOperations to get JSON metadata files from
+   * @param recursive When true, recursively retrieves all the reachable JSON 
metadata files.
+   *                 When false, gets the all the JSON metadata files only 
from the current metadata.
+   * @return locations of JSON metadata files
+   */
+  public static Set<String> metadataFileLocations(TableOperations ops, boolean 
recursive) {
+    Set<String> metadataFileLocations = Sets.newHashSet();
+    TableMetadata tableMetadata = ops.current();
+    metadataFileLocations.add(tableMetadata.metadataFileLocation());
+    metadataFileLocations(tableMetadata, metadataFileLocations, ops.io(), 
recursive);
+    return metadataFileLocations;
+  }
+
+  private static void metadataFileLocations(TableMetadata metadata, 
Set<String> metaFiles,
+                                            FileIO io, boolean recursive) {
+    List<TableMetadata.MetadataLogEntry> metadataLogEntries = 
metadata.previousFiles();
+    if (metadataLogEntries.size() > 0) {
+      for (TableMetadata.MetadataLogEntry metadataLogEntry : 
metadataLogEntries) {
+        metaFiles.add(metadataLogEntry.file());
+      }
+      if (recursive) {
+        String metadataFileLocation = metadataLogEntries.get(0).file();
+        try {
+          TableMetadata newMetadata = TableMetadataParser.read(io, 
metadataFileLocation);
+          metadataFileLocations(newMetadata, metaFiles, io, recursive);
+        } catch (Exception e) {
+          LOG.error("Failed to load {}", metadataFileLocation, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Returns locations of manifest lists in a table.
+   *
+   * @param table table for which manifestList needs to be fetched
+   * @return the paths of the Manifest Lists
+   */
+  public static List<String> manifestListLocations(Table table) {
+    Iterable<Snapshot> snapshots = table.snapshots();
+    List<String> manifestListLocations = new ArrayList<>();

Review comment:
       nit: `Lists.newArrayList()`

##########
File path: core/src/test/java/org/apache/iceberg/util/TestReachableFileUtil.java
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DataFiles;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.ReachableFileUtil;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.types.Types;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+
+public class TestReachableFileUtil {
+  private static final HadoopTables TABLES = new HadoopTables(new 
Configuration());
+  private static final Schema SCHEMA = new Schema(
+      optional(1, "c1", Types.IntegerType.get()),
+      optional(2, "c2", Types.StringType.get())
+  );
+
+  private static final PartitionSpec SPEC = 
PartitionSpec.builderFor(SCHEMA).identity("c1").build();
+
+  private static final DataFile FILE_A = DataFiles.builder(SPEC)
+      .withPath("/path/to/data-a.parquet")
+      .withFileSizeInBytes(10)
+      .withRecordCount(1)
+      .build();
+  private static final DataFile FILE_B = DataFiles.builder(SPEC)
+      .withPath("/path/to/data-b.parquet")
+      .withFileSizeInBytes(10)
+      .withRecordCount(1)
+      .build();
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  private Table table;
+
+  @Before
+  public void setupTableLocation() throws Exception {
+    File tableDir = temp.newFolder();
+    String tableLocation = tableDir.toURI().toString();
+    this.table = TABLES.create(SCHEMA, SPEC, Maps.newHashMap(), tableLocation);
+  }
+

Review comment:
       nit: extra line

##########
File path: 
spark/src/main/java/org/apache/iceberg/spark/actions/BaseSparkAction.java
##########
@@ -109,40 +110,6 @@ protected JobGroupInfo newJobGroupInfo(String groupId, 
String desc) {
     return new JobGroupInfo(groupId + "-" + JOB_COUNTER.incrementAndGet(), 
desc, false);
   }
 
-  /**
-   * Returns all the path locations of all Manifest Lists for a given list of 
snapshots
-   * @param snapshots snapshots
-   * @return the paths of the Manifest Lists
-   */
-  private List<String> getManifestListPaths(Iterable<Snapshot> snapshots) {

Review comment:
       Yeah, we should clean up `BaseAction`. I am fine doing that in a 
follow-up PR too. @karuppayya, could you submit one when the current is in?




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to