Skip to content

Commit

Permalink
AWS: Glue catalog strip trailing slash on DB URI (apache#8870)
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh-jahagirdar authored Oct 19, 2023
1 parent 45da568 commit d92be9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ protected String defaultWarehouseLocation(TableIdentifier tableIdentifier) {
.build());
String dbLocationUri = response.database().locationUri();
if (dbLocationUri != null) {
dbLocationUri = LocationUtil.stripTrailingSlash(dbLocationUri);
return String.format("%s/%s", dbLocationUri, tableIdentifier.name());
}

Expand Down Expand Up @@ -514,7 +515,9 @@ public Map<String, String> loadNamespaceMetadata(Namespace namespace)
Map<String, String> result = Maps.newHashMap(database.parameters());

if (database.locationUri() != null) {
result.put(IcebergToGlueConverter.GLUE_DB_LOCATION_KEY, database.locationUri());
result.put(
IcebergToGlueConverter.GLUE_DB_LOCATION_KEY,
LocationUtil.stripTrailingSlash(database.locationUri()));
}

if (database.description() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ public void testDefaultWarehouseLocationDbUri() {
Assertions.assertThat(location).isEqualTo("s3://bucket2/db/table");
}

@Test
public void testDefaultWarehouseLocationDbUriTrailingSlash() {
Mockito.doReturn(
GetDatabaseResponse.builder()
.database(Database.builder().name("db").locationUri("s3://bucket2/db/").build())
.build())
.when(glue)
.getDatabase(Mockito.any(GetDatabaseRequest.class));
String location = glueCatalog.defaultWarehouseLocation(TableIdentifier.of("db", "table"));

Assertions.assertThat(location).isEqualTo("s3://bucket2/db/table");
}

@Test
public void testDefaultWarehouseLocationCustomCatalogId() {
GlueCatalog catalogWithCustomCatalogId = new GlueCatalog();
Expand Down Expand Up @@ -478,9 +491,15 @@ public void testListNamespacesBadName() {
public void testLoadNamespaceMetadata() {
Map<String, String> parameters = Maps.newHashMap();
parameters.put("key", "val");
parameters.put(IcebergToGlueConverter.GLUE_DB_LOCATION_KEY, "s3://bucket2/db");
Mockito.doReturn(
GetDatabaseResponse.builder()
.database(Database.builder().name("db1").parameters(parameters).build())
.database(
Database.builder()
.name("db1")
.parameters(parameters)
.locationUri("s3://bucket2/db/")
.build())
.build())
.when(glue)
.getDatabase(Mockito.any(GetDatabaseRequest.class));
Expand Down

0 comments on commit d92be9b

Please sign in to comment.