jackye1995 commented on code in PR #10877:
URL: https://github.com/apache/iceberg/pull/10877#discussion_r1722436641


##########
core/src/main/java/org/apache/iceberg/rest/RESTUtil.java:
##########
@@ -194,15 +192,34 @@ public static String decodeString(String encoded) {
    * @return UTF-8 encoded string representing the namespace, suitable for use 
as a URL parameter
    */
   public static String encodeNamespace(Namespace ns) {
-    Preconditions.checkArgument(ns != null, "Invalid namespace: null");
-    String[] levels = ns.levels();
+    return encodeNamespace(ns, NAMESPACE_ESCAPED_SEPARATOR);
+  }
+
+  /**
+   * Returns a String representation of a namespace that is suitable for use 
in a URL / URI.
+   *
+   * <p>This function needs to be called when a namespace is used as a path 
variable (or query
+   * parameter etc.), to format the namespace per the spec.
+   *
+   * <p>{@link RESTUtil#decodeNamespace(String, String)} should be used to 
parse the namespace from
+   * a URL parameter.
+   *
+   * @param namespace namespace to encode
+   * @param separator The namespace separator to use for encoding
+   * @return UTF-8 encoded string representing the namespace, suitable for use 
as a URL parameter
+   */
+  public static String encodeNamespace(Namespace namespace, String separator) {
+    Preconditions.checkArgument(namespace != null, "Invalid namespace: null");
+    Preconditions.checkArgument(
+        !Strings.isNullOrEmpty(separator), "Invalid separator: null or empty");
+    String[] levels = namespace.levels();
     String[] encodedLevels = new String[levels.length];
 
     for (int i = 0; i < levels.length; i++) {
       encodedLevels[i] = encodeString(levels[i]);
     }
 
-    return NAMESPACE_ESCAPED_JOINER.join(encodedLevels);
+    return Joiner.on(separator).join(encodedLevels);

Review Comment:
   In that case could we make it clear in the description, that the separator 
is expected to be used as is, and not URL-encoded? I guess `:` is not a good 
example, since `:` in URL path is not an issue. But if it is `/`, then I think 
this would imply you should use `%2F` instead of `/` as the separator value.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to