Skip to content

Commit

Permalink
Nessie: Strip trailing slash for warehouse location (#9415)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat authored Jan 5, 2024
1 parent 0bf2602 commit c416c29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -147,15 +148,15 @@ public void initialize(
.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);
closeableGroup.setSuppressCloseFailure(true);
}

@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
Expand Down Expand Up @@ -183,7 +184,8 @@ private String validateWarehouseLocation(String name, Map<String, String> catalo
catalogOptions);
throw new IllegalStateException("Parameter 'warehouse' not set, Nessie can't store data.");
}
return warehouseLocation;

return LocationUtil.stripTrailingSlash(warehouseLocation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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;
Expand Down Expand Up @@ -160,4 +162,15 @@ protected boolean supportsServerSideRetry() {
public void testConcurrentCreateTransaction() {
super.testConcurrentCreateTransaction();
}

@Test
public void testWarehouseLocationWithTrailingSlash() {
Assertions.assertThat(catalog.defaultWarehouseLocation(TABLE))
.startsWith(
LocationUtil.stripTrailingSlash(temp.toUri().toString())
+ "/"
+ TABLE.namespace()
+ "/"
+ TABLE.name());
}
}

0 comments on commit c416c29

Please sign in to comment.