vinishjail97 commented on code in PR #957:
URL: https://github.com/apache/incubator-xtable/pull/957#discussion_r4201200857
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaPathUtils.java:
##########
@@ -51,6 +56,35 @@ public static String getFullPathToFile(String tableBasePath,
String dataFilePath
: tableBasePath + Path.SEPARATOR + dataFilePath;
}
+ /**
+ * Returns the path to record in an AddFile or RemoveFile action for a data
file.
+ *
+ * <p>A file under the table base path is recorded relative to it, since
relative paths seem more
+ * commonly supported by query engines. A file outside the base path, for
example one written to a
+ * separate data location of an Iceberg source, is recorded with its
absolute path, since a
+ * relative path cannot point to it.
+ *
+ * @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
+ */
+ public static String getPathForDeltaLog(String tableBasePath, String
dataFilePath) {
+ return isUnderBasePath(tableBasePath, dataFilePath)
+ ? PathUtils.getRelativePath(dataFilePath, tableBasePath)
+ : dataFilePath;
+ }
+
+ private static boolean isUnderBasePath(String tableBasePath, String
dataFilePath) {
+ URI file = new Path(dataFilePath).toUri();
Review Comment:
Thanks, added the quick `:` check in 190b1b0, so a path without a scheme now
returns before any `Path` is built. `isAbsolutePath` on the source side no
longer parses a `Path` at all. A data file path with a scheme still goes
through one `Path` parse in `isUnderBasePath` to compare the authority and
path; a string-only version of that comparison got fiddly, so I kept it as is,
but happy to revisit if you think it is worth it.
--
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]