This is an automated email from the ASF dual-hosted git repository.
amoghj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new defef48e21 Core: Only trim trailing slash when warehouse location is
not root path (#9619)
defef48e21 is described below
commit defef48e21936357e0921d1738f211bb32e85e49
Author: Abid Mohammed <[email protected]>
AuthorDate: Tue Feb 6 14:57:07 2024 -0800
Core: Only trim trailing slash when warehouse location is not root path
(#9619)
Co-authored-by: Abid Mohammed <[email protected]>
Co-authored-by: Eduard Tudenhoefner <[email protected]>
---
.../java/org/apache/iceberg/util/LocationUtil.java | 2 +-
.../org/apache/iceberg/util/TestLocationUtil.java | 26 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
b/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
index 1927861557..4003071492 100644
--- a/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
+++ b/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
@@ -28,7 +28,7 @@ public class LocationUtil {
Preconditions.checkArgument(!Strings.isNullOrEmpty(path), "path must not
be null or empty");
String result = path;
- while (result.endsWith("/")) {
+ while (!result.endsWith("://") && result.endsWith("/")) {
result = result.substring(0, result.length() - 1);
}
return result;
diff --git a/core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java
b/core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java
index f557352299..2775004616 100644
--- a/core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java
+++ b/core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java
@@ -58,4 +58,30 @@ public class TestLocationUtil {
.hasMessage("path must not be null or empty");
}
}
+
+ @Test
+ void testDoNotStripTrailingSlashForRootPath() {
+ String rootPath = "blobstore://";
+ assertThat(LocationUtil.stripTrailingSlash(rootPath))
+ .as("Should be root path")
+ .isEqualTo(rootPath);
+ }
+
+ @Test
+ void testStripTrailingSlashForRootPathWithTrailingSlash() {
+ String rootPath = "blobstore://";
+ String rootPathWithTrailingSlash = rootPath + "/";
+ assertThat(LocationUtil.stripTrailingSlash(rootPathWithTrailingSlash))
+ .as("Should be root path")
+ .isEqualTo(rootPath);
+ }
+
+ @Test
+ void testStripTrailingSlashForRootPathWithTrailingSlashes() {
+ String rootPath = "blobstore://";
+ String rootPathWithMultipleTrailingSlash = rootPath + "///";
+
assertThat(LocationUtil.stripTrailingSlash(rootPathWithMultipleTrailingSlash))
+ .as("Should be root path")
+ .isEqualTo(rootPath);
+ }
}