zhjwpku commented on code in PR #1124:
URL: https://github.com/apache/iceberg-cpp/pull/1124#discussion_r4576775663


##########
src/iceberg/util/location_util.cc:
##########
@@ -66,4 +66,63 @@ std::string_view LocationUtil::ParseScheme(std::string_view 
location) {
   return candidate;
 }
 
+bool LocationUtil::HasScheme(std::string_view location) {
+  // RFC 3986 section 3.1: a URI starts with `scheme ":"`, so the scheme is
+  // everything before the first colon. The spec ("Paths in Metadata") calls a
+  // path absolute iff it starts with such a scheme, as Java's
+  // LocationUtil.hasScheme does.
+  const auto colon = location.find(':');
+  return colon != std::string_view::npos && IsValidScheme(location.substr(0, 
colon));
+}
+
+std::string LocationUtil::ResolveLocation(std::string_view table_location,
+                                          std::string_view location) {
+  if (HasScheme(location)) {
+    return std::string(location);
+  }
+  // The spec ("Path Resolution",
+  // https://iceberg.apache.org/spec/#path-resolution) defines this as a plain
+  // string join with `/`.
+  // It is not RFC 3986 reference resolution (section 5.2), which the spec
+  // rules out: a URI library would remove `.`/`..` segments, merge `//`, and
+  // could decode or re-encode `%XX`, producing a path that differs from the
+  // one the writer stored. Both parts are opaque strings in whatever encoding
+  // the writer used, and they are copied byte for byte.
+  //
+  // The spec recommends a table location that does not end in `/`, because

Review Comment:
   I'm not sure this is the right solution, but from the spec I can see the 
trailing `/` is kept, I tend to align with spec[1], correct me if I'm wrong :-)
   
   [1] 
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/util/LocationUtil.java



-- 
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]

Reply via email to