szehon-ho commented on code in PR #15173:
URL: https://github.com/apache/iceberg/pull/15173#discussion_r2756282534
##########
core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java:
##########
@@ -754,14 +762,28 @@ public static String fileName(String path) {
return filename;
}
- /** Relativize a path. */
+ /**
+ * Compute the relative path from a prefix to a given path.
+ *
+ * <p>If the path is under the prefix, returns the portion after the prefix.
If the path equals
+ * the prefix (representing the root directory itself), returns an empty
string.
+ *
+ * <p>Trailing separators are normalized: "/a" and "/a/" are treated as
equivalent for both path
+ * and prefix. This allows flexibility when paths come from different
sources that may or may not
+ * include trailing separators.
+ *
+ * @param path absolute path to relativize
+ * @param prefix prefix path to remove
+ * @return relative path from prefix to path, or empty string if path equals
prefix
+ * @throws IllegalArgumentException if path is not under or equal to prefix
+ */
public static String relativize(String path, String prefix) {
String toRemove = maybeAppendFileSeparator(prefix);
- if (!path.startsWith(toRemove)) {
+ if (!path.startsWith(toRemove) &&
!maybeAppendFileSeparator(path).equals(toRemove)) {
Review Comment:
could we check if the following works?
```
String toRelativize = maybeAppendFileSeparator(path);
if (!toRelative.startsWith(toRemove) && !toRelative.equals(toRemove))
throw new IllegalArgumentException();
return toRelativize.substring(toRemove.length());
```
im not a big fan of the path.length <= toRemove.length() check as it does
seem a bit too free-form, though i understand the previous check should catch
the case it wasnt intended for (when path does not have trailing slash)
--
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]