Baunsgaard opened a new pull request, #15173:
URL: https://github.com/apache/iceberg/pull/15173
### What
Fix `RewriteTablePathUtil.relativize()` to handle the edge case where `path`
equals `prefix` exactly.
### Why
Currently, `relativize()` fails when a path equals the prefix (e.g.,
`write.data.path` set to the table root). This breaks `rewrite_table_path` for
tables with properties pointing to the table location itself.
**Example failure:**
// Throws IllegalArgumentException instead of returning ""
RewriteTablePathUtil.relativize("/path/to/table", "/path/to/table");
**Use case:**
Storage migration or replication where `write.data.path = table location`.
### How
Added a check for exact match after normalizing trailing separators:
```java
// Handle exact match where path equals prefix (without trailing separator)
if (maybeAppendFileSeparator(path).equals(toRemove)) {
return "";
}
```
### Changes
- **`RewriteTablePathUtil.java`**: Fix `relativize()` + updated Javadoc for
`relativize()` and `newPath()`
- **`TestRewriteTablePathUtil.java`**: Added 10 test methods covering:
- Normal relativization
- Path equals prefix (the fix)
- Trailing separator variations
- Invalid path rejection
- Subdirectory scenarios (backup/restore)
- Overlapping name rejection (`/table` vs `/table-old`)
### Testing
```bash
./gradlew :iceberg-core:test --tests
"org.apache.iceberg.TestRewriteTablePathUtil"
```
--
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]