anoopj commented on code in PR #16174:
URL: https://github.com/apache/iceberg/pull/16174#discussion_r3291453766


##########
core/src/main/java/org/apache/iceberg/util/LocationUtil.java:
##########
@@ -64,20 +64,29 @@ public static String tableLocation(TableIdentifier 
tableIdentifier, boolean useU
    * section 3.1</a>.
    */
   private static boolean hasScheme(String location) {
+    // RFC 3986 section 3.1: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." 
)

Review Comment:
   Agree. Done. 



##########
core/src/main/java/org/apache/iceberg/util/LocationUtil.java:
##########
@@ -57,4 +57,70 @@ public static String tableLocation(TableIdentifier 
tableIdentifier, boolean useU
       return tableIdentifier.name();
     }
   }
+
+  /**
+   * Returns true if the location contains a URI scheme (e.g. {@code s3:}, 
{@code hdfs:}, {@code
+   * file:}), per <a 
href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1";>RFC 3986
+   * section 3.1</a>.
+   */
+  private static boolean hasScheme(String location) {
+    // RFC 3986 section 3.1: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." 
)
+    for (int i = 0; i < location.length(); i += 1) {
+      char ch = location.charAt(i);
+      if (ch == ':') {
+        return i > 0;
+      }
+
+      if (!isSchemeChar(ch, i)) {
+        return false;
+      }
+    }
+
+    return false;
+  }
+
+  private static boolean isSchemeChar(char ch, int position) {
+    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
+      return true;
+    }
+
+    return position > 0 && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' 
|| ch == '.');
+  }
+
+  /**
+   * Resolves a location against a table location. If the location has a URI 
scheme, it is returned
+   * as-is. Otherwise, the table location and the relative location are joined 
by the URI separator
+   * character {@code /}.
+   *
+   * <p>The separator is appended unconditionally; {@code tableLocation} is 
expected not to end with
+   * {@code /} and {@code location} is expected not to start with {@code /}. 
Otherwise the result
+   * will contain a duplicate {@code //}.
+   */
+  public static String resolveLocation(String tableLocation, String location) {
+    if (hasScheme(location)) {
+      return location;
+    }
+
+    return tableLocation + "/" + location;

Review Comment:
   Done. 



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