Baunsgaard commented on code in PR #15173:
URL: https://github.com/apache/iceberg/pull/15173#discussion_r2745888879
##########
core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java:
##########
@@ -754,14 +759,33 @@ 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: both "/a" and "/a/" are treated as
equivalent prefixes.
+ *
+ * @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)) {
- throw new IllegalArgumentException(
- String.format("Path %s does not start with %s", path, toRemove));
+
+ if (path.startsWith(toRemove)) {
Review Comment:
With the simplified implementation you and @dramaticlly suggested, we no
longer need `maybeAppendFileSeparator(path)` in the `startsWith` check.
--
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]