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


##########
core/src/main/java/org/apache/iceberg/util/LocationUtil.java:
##########
@@ -57,4 +57,69 @@ public static String tableLocation(TableIdentifier 
tableIdentifier, boolean useU
       return tableIdentifier.name();
     }
   }
+
+  private static final int MAX_SCHEME_LENGTH = 10;
+
+  /**
+   * Returns true if the location contains a URI scheme (e.g. {@code s3:}, 
{@code hdfs:}, {@code
+   * file:}). Checks at most the first 10 characters for a {@code :} preceded 
by alphanumeric
+   * characters, 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) {
+    if (location == null || location.isEmpty()) {
+      return false;
+    }
+
+    // Early termination for relative locations since most commonly start with 
/
+    if (location.charAt(0) == '/') {
+      return false;
+    }
+
+    int limit = Math.min(location.length(), MAX_SCHEME_LENGTH);
+    for (int i = 0; i < limit; i += 1) {
+      char ch = location.charAt(i);
+      if (ch == ':') {
+        return i > 0;
+      }
+
+      if (!Character.isLetterOrDigit(ch)) {
+        return false;
+      }
+    }
+
+    return false;
+  }
+
+  /**
+   * Resolves a relative location against a table location. If the location 
has a URI scheme, it is
+   * returned as-is. Otherwise, the location is appended to the table location 
without any
+   * additional separator.
+   */
+  public static String resolveLocation(String location, String tableLocation) {
+    Preconditions.checkArgument(tableLocation != null, "Table location must 
not be null");
+    if (location == null || hasScheme(location)) {

Review Comment:
   When would location be null?



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