Baunsgaard commented on code in PR #15173:
URL: https://github.com/apache/iceberg/pull/15173#discussion_r2746041601
##########
core/src/test/java/org/apache/iceberg/TestRewriteTablePathUtil.java:
##########
@@ -80,4 +81,89 @@ public void testStagingPathWithNoMiddlePart() {
RewriteTablePathUtil.stagingPath(fileDirectlyUnderPrefix,
sourcePrefix, stagingDir);
assertThat(newMethodResult).isEqualTo("/staging/file.parquet");
}
+
+ @Test
+ public void testRelativizePathUnderPrefix() {
+ // Normal case: path is under prefix
+ assertThat(RewriteTablePathUtil.relativize("/a/b/c",
"/a")).isEqualTo("b/c");
+ assertThat(RewriteTablePathUtil.relativize("/a/b", "/a")).isEqualTo("b");
+
assertThat(RewriteTablePathUtil.relativize("/source/table/data/file.parquet",
"/source/table"))
+ .isEqualTo("data/file.parquet");
+ }
+
+ @Test
+ public void testRelativizePathEqualsPrefix() {
+ // Edge case: path equals prefix exactly (issue #15172)
+ assertThat(RewriteTablePathUtil.relativize("/a", "/a")).isEqualTo("");
+ assertThat(RewriteTablePathUtil.relativize("/source/table",
"/source/table")).isEqualTo("");
+ assertThat(RewriteTablePathUtil.relativize("s3://bucket/warehouse",
"s3://bucket/warehouse"))
+ .isEqualTo("");
+ }
+
+ @Test
+ public void testRelativizePathEqualsPrefixWithTrailingSeparator() {
+ // Edge case: path equals prefix with trailing separator on path
+ assertThat(RewriteTablePathUtil.relativize("/a/", "/a")).isEqualTo("");
+ assertThat(RewriteTablePathUtil.relativize("/source/table/",
"/source/table")).isEqualTo("");
+
+ // Edge case: prefix has trailing separator
+ assertThat(RewriteTablePathUtil.relativize("/a", "/a/")).isEqualTo("");
Review Comment:
I would have expected that case to work. I added explicit handling for it,
by modifying your suggested code to do the maybe append file separator :
` if (!path.startsWith(toRemove) &&
!maybeAppendFileSeparator(path).equals(toRemove)) {`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]