-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* multiple prefixes * stable tests * autolint * add todos * implement todos * autolint * more fixes * autolint * fix test * fix check * move tenant ID to env var * another fix * autolint * fix another location check (?) * autolint * clean up for review * polish * autolint * adjustments per review * autolint
- Loading branch information
1 parent
bb47225
commit 6c02252
Showing
12 changed files
with
212 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.core.storage; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.net.URI; | ||
import org.apache.polaris.core.storage.azure.AzureLocation; | ||
|
||
/** An abstraction over a storage location */ | ||
public class StorageLocation { | ||
private final String location; | ||
|
||
/** Create a StorageLocation from a String path */ | ||
public static StorageLocation of(String location) { | ||
// TODO implement StorageLocation for all supported file systems and add isValidLocation | ||
if (AzureLocation.isAzureLocation(location)) { | ||
return new AzureLocation(location); | ||
} else { | ||
return new StorageLocation(location); | ||
} | ||
} | ||
|
||
protected StorageLocation(@NotNull String location) { | ||
if (location == null) { | ||
this.location = null; | ||
} else if (location.startsWith("file:/") && !location.startsWith("file:///")) { | ||
this.location = URI.create(location.replaceFirst("file:/+", "file:///")).toString(); | ||
} else { | ||
this.location = URI.create(location).toString(); | ||
} | ||
} | ||
|
||
/** If a path doesn't end in `/`, this will add one */ | ||
protected final String ensureTrailingSlash(String location) { | ||
if (location == null || location.endsWith("/")) { | ||
return location; | ||
} else { | ||
return location + "/"; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return location.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof StorageLocation) { | ||
return location.equals(((StorageLocation) obj).location); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return location; | ||
} | ||
|
||
/** | ||
* Returns true if this StorageLocation's location string starts with the other StorageLocation's | ||
* location string | ||
*/ | ||
public boolean isChildOf(StorageLocation potentialParent) { | ||
if (this.location == null || potentialParent.location == null) { | ||
return false; | ||
} else { | ||
String slashTerminatedLocation = ensureTrailingSlash(this.location); | ||
String slashTerminatedParentLocation = ensureTrailingSlash(potentialParent.location); | ||
return slashTerminatedLocation.startsWith(slashTerminatedParentLocation); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.polaris.service.storage.azure; | ||
|
||
import org.apache.polaris.core.storage.StorageLocation; | ||
import org.apache.polaris.core.storage.azure.AzureLocation; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -34,12 +35,28 @@ public void testLocation() { | |
Assertions.assertThat(azureLocation.getFilePath()).isEqualTo("myfile"); | ||
} | ||
|
||
@Test | ||
public void testWasbLocation() { | ||
String uri = "wasb://[email protected]/myfile"; | ||
AzureLocation azureLocation = new AzureLocation(uri); | ||
Assertions.assertThat(azureLocation.getContainer()).isEqualTo("container"); | ||
Assertions.assertThat(azureLocation.getStorageAccount()).isEqualTo("storageaccount"); | ||
Assertions.assertThat(azureLocation.getEndpoint()).isEqualTo("blob.core.windows.net"); | ||
Assertions.assertThat(azureLocation.getFilePath()).isEqualTo("myfile"); | ||
} | ||
|
||
@Test | ||
public void testCrossSchemeComparisons() { | ||
StorageLocation abfsLocation = | ||
AzureLocation.of("abfss://[email protected]/some/file/x"); | ||
StorageLocation wasbLocation = | ||
AzureLocation.of("wasb://[email protected]/some/file"); | ||
Assertions.assertThat(abfsLocation).isNotEqualTo(wasbLocation); | ||
Assertions.assertThat(abfsLocation.isChildOf(wasbLocation)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testLocation_negative_cases() { | ||
Assertions.assertThatThrownBy( | ||
() -> | ||
new AzureLocation("wasbs://[email protected]/myfile")) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
Assertions.assertThatThrownBy( | ||
() -> new AzureLocation("abfss://storageaccount.blob.core.windows.net/myfile")) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
|
Oops, something went wrong.