Repository navigation
feat(util): add location resolve and relativize helpers #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| /// \file iceberg/util/location_util.h | ||
| /// \brief Provide location path utilities. | ||
|
|
||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
|
|
@@ -39,6 +40,32 @@ class ICEBERG_EXPORT LocationUtil { | |
| /// not validated. | ||
| static std::string_view ParseScheme(std::string_view location); | ||
|
|
||
| /// \brief Whether a location starts with a URI scheme. | ||
| /// | ||
| /// This is the spec's test for an absolute path (see "Paths in Metadata"): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we copy the descriptions from java impl?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. but the difference needs to be called out. So will make this change after previous thread is resolved. |
||
| /// the text before the first colon must be a non-empty RFC 3986 scheme. It | ||
| /// is strict on every platform: unlike ParseScheme, a single letter such as | ||
| /// `C:` counts as a scheme. | ||
| static bool HasScheme(std::string_view location); | ||
|
|
||
| /// \brief Resolve a location against a table location. | ||
| /// | ||
| /// A location with a URI scheme is absolute and is returned unchanged. | ||
| /// Otherwise the result is `table_location + "/" + location`, with no `/` | ||
| /// added when the table location already ends in one. The join does not | ||
| /// interpret `.` or `..`, and a location starting with `/` yields `//`. | ||
| static std::string ResolveLocation(std::string_view table_location, | ||
| std::string_view location); | ||
|
|
||
| /// \brief Relativize a location against a table location. | ||
| /// | ||
| /// If the location starts with the table location immediately followed by | ||
| /// `/`, the remainder after that separator is returned. Otherwise the | ||
| /// location is returned unchanged. A table location that ends in `/` | ||
| /// already includes the separator. | ||
| static std::string_view RelativizeLocation(std::string_view table_location, | ||
| std::string_view location); | ||
|
|
||
| static std::string_view StripTrailingSlash(std::string_view path) { | ||
| if (path.empty()) { | ||
| return ""; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote comment from java:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec says exactly this:
https://iceberg.apache.org/spec/#path-resolution
So it recommend not to include the trailing / for table location, but this diff go ahead and enforce that. It's very problematic for S3 if you include double back slash as they are not treated as file path. So s3://foo//bar is actually different then s3://foo/bar. Super confusing and error prone. That's why i just enforce that in the diff.
We could also add an assertion but I feel it's a bit too strong and there's an easy remedy.