the-other-tim-brown commented on code in PR #986:
URL: https://github.com/apache/incubator-xtable/pull/986#discussion_r4656081978
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaPathUtils.java:
##########
@@ -66,12 +69,50 @@ public static String getFullPathToFile(String
tableBasePath, String dataFilePath
*
* @param tableBasePath the table base path
* @param dataFilePath the path to the data file, relative or absolute
- * @return the path to record in the Delta log
+ * @return the path to record in the Delta log, URI-encoded as the Delta
protocol expects
*/
public static String getPathForDeltaLog(String tableBasePath, String
dataFilePath) {
Review Comment:
I think we can simplify the approach with something along the lines of:
```
// RFC 3986 path characters minus ':', so a relative first segment can't be
read as a scheme.
private static final Escaper PATH_ESCAPER = new
PercentEscaper("-._~!$&'()*+,;=@/", false);
private static final Pattern SCHEME_AUTHORITY =
Pattern.compile("^[A-Za-z][A-Za-z0-9+.-]*://[^/]*");
public static String getPathForDeltaLog(String tableBasePath, String
dataFilePath) {
return encode(
isUnderBasePath(tableBasePath, dataFilePath)
? PathUtils.getRelativePath(dataFilePath, tableBasePath)
: dataFilePath);
}
private static String encode(String path) {
Matcher m = SCHEME_AUTHORITY.matcher(path);
int start = m.find() ? m.end() : 0;
return path.substring(0, start) +
PATH_ESCAPER.escape(path.substring(start));
}
private static String decode(String path) {
try {
// URLDecoder treats '+' as a space, which isn't true for URI paths.
return URLDecoder.decode(path.replace("+", "%2B"), "UTF-8");
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
return path; // not valid encoding, so it's an unencoded path from an
older XTable
}
}
```
--
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]