Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nessie: Strip trailing slash for warehouse location #9415

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Nessie: Strip trailing slash for warehouse location
  • Loading branch information
ajantha-bhat committed Jan 5, 2024
commit b6571e308d309acaaff96cf92168073d9ff0713d
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making this inline with other catalogs.
We can lookup the callers of LocationUtil.stripTrailingSlash

}

@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())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This testcase was failing without the fix as temp.toUri() was having trailing slash which was leading to double slash in the path.

+ "/"
+ TABLE.namespace()
+ "/"
+ TABLE.name());
}
}