This is an automated email from the ASF dual-hosted git repository.

aokolnychyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new b91bb9c  Core: Support retrieving version hint location for static 
tables (#2677)
b91bb9c is described below

commit b91bb9ce062b97efcb840008dce7552b83649e9a
Author: Anton Okolnychyi <[email protected]>
AuthorDate: Fri Jun 4 13:00:37 2021 -1000

    Core: Support retrieving version hint location for static tables (#2677)
---
 .../java/org/apache/iceberg/ReachableFileUtil.java     |  8 ++++++--
 .../org/apache/iceberg/util/TestReachableFileUtil.java | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/ReachableFileUtil.java 
b/core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
index 0197b4a..004e31c 100644
--- a/core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
+++ b/core/src/main/java/org/apache/iceberg/ReachableFileUtil.java
@@ -21,6 +21,7 @@ package org.apache.iceberg;
 
 import java.util.List;
 import java.util.Set;
+import org.apache.hadoop.fs.Path;
 import org.apache.iceberg.TableMetadata.MetadataLogEntry;
 import org.apache.iceberg.hadoop.Util;
 import org.apache.iceberg.io.FileIO;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
 public class ReachableFileUtil {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(ReachableFileUtil.class);
+  private static final String METADATA_FOLDER_NAME = "metadata";
 
   private ReachableFileUtil() {
   }
@@ -43,8 +45,10 @@ public class ReachableFileUtil {
    * @return the location of the version hint file
    */
   public static String versionHintLocation(Table table) {
-    TableOperations ops = ((HasTableOperations) table).operations();
-    return ops.metadataFileLocation(Util.VERSION_HINT_FILENAME);
+    // only Hadoop tables have a hint file and such tables have a fixed 
metadata layout
+    Path metadataPath = new Path(table.location(), METADATA_FOLDER_NAME);
+    Path versionHintPath = new Path(metadataPath, Util.VERSION_HINT_FILENAME);
+    return versionHintPath.toString();
   }
 
   /**
diff --git 
a/core/src/test/java/org/apache/iceberg/util/TestReachableFileUtil.java 
b/core/src/test/java/org/apache/iceberg/util/TestReachableFileUtil.java
index 257d25e..596bece 100644
--- a/core/src/test/java/org/apache/iceberg/util/TestReachableFileUtil.java
+++ b/core/src/test/java/org/apache/iceberg/util/TestReachableFileUtil.java
@@ -23,16 +23,20 @@ import java.io.File;
 import java.util.List;
 import java.util.Set;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.BaseTable;
 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.StaticTableOperations;
 import org.apache.iceberg.Table;
+import org.apache.iceberg.TableMetadata;
 import org.apache.iceberg.TableOperations;
 import org.apache.iceberg.TableProperties;
 import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.hadoop.Util;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
 import org.apache.iceberg.types.Types;
 import org.junit.Assert;
@@ -132,4 +136,18 @@ public class TestReachableFileUtil {
     Set<String> metadataFileLocations = 
ReachableFileUtil.metadataFileLocations(table, true);
     Assert.assertEquals(metadataFileLocations.size(), 2);
   }
+
+  @Test
+  public void testVersionHintWithStaticTables() {
+    TableOperations ops = ((HasTableOperations) table).operations();
+    TableMetadata metadata = ops.current();
+    String metadataFileLocation = metadata.metadataFileLocation();
+
+    StaticTableOperations staticOps = new 
StaticTableOperations(metadataFileLocation, table.io());
+    Table staticTable = new BaseTable(staticOps, metadataFileLocation);
+
+    String reportedVersionHintLocation = 
ReachableFileUtil.versionHintLocation(staticTable);
+    String expectedVersionHintLocation = 
ops.metadataFileLocation(Util.VERSION_HINT_FILENAME);
+    Assert.assertEquals(expectedVersionHintLocation, 
reportedVersionHintLocation);
+  }
 }

Reply via email to