You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by em...@apache.org on 2024/10/18 22:13:35 UTC
(polaris) branch main updated: Fix Azure path comparison when filePath is root ("/") (#385)
This is an automated email from the ASF dual-hosted git repository.
emaynard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 3191ea0c Fix Azure path comparison when filePath is root ("/") (#385)
3191ea0c is described below
commit 3191ea0c036d44c9be8959dc2c422d74d00e2a92
Author: Hung-An (Alvin) Chen <62...@users.noreply.github.com>
AuthorDate: Fri Oct 18 17:13:31 2024 -0500
Fix Azure path comparison when filePath is root ("/") (#385)
* Fix Azure path comparison
* Address comments
* Formatting
---
.../org/apache/polaris/core/storage/StorageLocation.java | 9 +++++++++
.../apache/polaris/core/storage/azure/AzureLocation.java | 7 ++++---
.../polaris/service/storage/azure/AzureLocationTest.java | 16 ++++++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
index 51def1fb..baad1f89 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
@@ -55,6 +55,15 @@ public class StorageLocation {
}
}
+ /** If a path doesn't start with `/`, this will add one */
+ protected final @NotNull String ensureLeadingSlash(@NotNull String location) {
+ if (location.startsWith("/")) {
+ return location;
+ } else {
+ return "/" + location;
+ }
+ }
+
@Override
public int hashCode() {
return location.hashCode();
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
index e7211593..a5f0b218 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
@@ -108,9 +108,10 @@ public class AzureLocation extends StorageLocation {
AzureLocation potentialAzureParent = (AzureLocation) potentialParent;
if (this.container.equals(potentialAzureParent.container)) {
if (this.storageAccount.equals(potentialAzureParent.storageAccount)) {
- String slashTerminatedFilePath = ensureTrailingSlash(this.filePath);
- String slashTerminatedParentFilePath = ensureTrailingSlash(potentialAzureParent.filePath);
- return slashTerminatedFilePath.startsWith(slashTerminatedParentFilePath);
+ String formattedFilePath = ensureLeadingSlash(ensureTrailingSlash(this.filePath));
+ String formattedParentFilePath =
+ ensureLeadingSlash(ensureTrailingSlash(potentialAzureParent.filePath));
+ return formattedFilePath.startsWith(formattedParentFilePath);
}
}
}
diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureLocationTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureLocationTest.java
index 8040d289..f8cf168e 100644
--- a/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureLocationTest.java
+++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureLocationTest.java
@@ -55,6 +55,22 @@ public class AzureLocationTest {
Assertions.assertThat(abfsLocation.isChildOf(wasbLocation)).isTrue();
}
+ @Test
+ public void testLocationComparisons() {
+ StorageLocation location =
+ AzureLocation.of("abfss://container-dash@acc.blob.core.windows.net/some_file/metadata");
+ StorageLocation parentLocation =
+ AzureLocation.of("abfss://container-dash@acc.blob.core.windows.net");
+ StorageLocation parentLocationTrailingSlash =
+ AzureLocation.of("abfss://container-dash@acc.blob.core.windows.net/");
+
+ Assertions.assertThat(location).isNotEqualTo(parentLocation);
+ Assertions.assertThat(location).isNotEqualTo(parentLocationTrailingSlash);
+
+ Assertions.assertThat(location.isChildOf(parentLocation)).isTrue();
+ Assertions.assertThat(location.isChildOf(parentLocationTrailingSlash)).isTrue();
+ }
+
@Test
public void testLocation_negative_cases() {
Assertions.assertThatThrownBy(