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

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


The following commit(s) were added to refs/heads/main by this push:
     new c416c29894 Nessie: Strip trailing slash for warehouse location (#9415)
c416c29894 is described below

commit c416c298943c9c21928e71f37662b8ffbe11b56b
Author: Ajantha Bhat <[email protected]>
AuthorDate: Fri Jan 5 17:42:25 2024 +0530

    Nessie: Strip trailing slash for warehouse location (#9415)
---
 .../main/java/org/apache/iceberg/nessie/NessieCatalog.java  |  8 +++++---
 .../java/org/apache/iceberg/nessie/TestNessieCatalog.java   | 13 +++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java 
b/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
index 13a7d70cc4..a242bfeb67 100644
--- a/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
+++ b/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
@@ -41,6 +41,7 @@ import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTest
 import org.apache.iceberg.relocated.com.google.common.base.Joiner;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.util.LocationUtil;
 import org.apache.iceberg.view.BaseMetastoreViewCatalog;
 import org.apache.iceberg.view.ViewOperations;
 import org.projectnessie.client.NessieClientBuilder;
@@ -147,7 +148,7 @@ public class NessieCatalog extends BaseMetastoreViewCatalog
             .putAll(DEFAULT_CATALOG_OPTIONS)
             .putAll(Preconditions.checkNotNull(catalogOptions, "catalogOptions 
must be non-null"))
             .buildKeepingLast();
-    this.warehouseLocation = validateWarehouseLocation(name, catalogOptions);
+    this.warehouseLocation = warehouseLocation(name, catalogOptions);
     this.closeableGroup = new CloseableGroup();
     closeableGroup.addCloseable(client);
     closeableGroup.addCloseable(fileIO);
@@ -155,7 +156,7 @@ public class NessieCatalog extends BaseMetastoreViewCatalog
   }
 
   @SuppressWarnings("checkstyle:HiddenField")
-  private String validateWarehouseLocation(String name, Map<String, String> 
catalogOptions) {
+  private String warehouseLocation(String name, Map<String, String> 
catalogOptions) {
     String warehouseLocation = 
catalogOptions.get(CatalogProperties.WAREHOUSE_LOCATION);
     if (warehouseLocation == null) {
       // Explicitly log a warning, otherwise the thrown exception can get list 
in the "silent-ish
@@ -183,7 +184,8 @@ public class NessieCatalog extends BaseMetastoreViewCatalog
           catalogOptions);
       throw new IllegalStateException("Parameter 'warehouse' not set, Nessie 
can't store data.");
     }
-    return warehouseLocation;
+
+    return LocationUtil.stripTrailingSlash(warehouseLocation);
   }
 
   @Override
diff --git 
a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java 
b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java
index 760ff07011..dfa8f0a62a 100644
--- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java
+++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java
@@ -25,6 +25,8 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.iceberg.CatalogProperties;
 import org.apache.iceberg.catalog.CatalogTests;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.util.LocationUtil;
+import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
@@ -160,4 +162,15 @@ public class TestNessieCatalog extends 
CatalogTests<NessieCatalog> {
   public void testConcurrentCreateTransaction() {
     super.testConcurrentCreateTransaction();
   }
+
+  @Test
+  public void testWarehouseLocationWithTrailingSlash() {
+    Assertions.assertThat(catalog.defaultWarehouseLocation(TABLE))
+        .startsWith(
+            LocationUtil.stripTrailingSlash(temp.toUri().toString())
+                + "/"
+                + TABLE.namespace()
+                + "/"
+                + TABLE.name());
+  }
 }

Reply via email to