Class RESTUtil

java.lang.Object
org.apache.iceberg.rest.RESTUtil

public class RESTUtil extends Object
  • Field Details

  • Method Details

    • stripTrailingSlash

      public static String stripTrailingSlash(String path)
    • merge

      public static Map<String,String> merge(Map<String,String> target, Map<String,String> updates)
      Merge updates into a target string map.
      Parameters:
      target - a map to update
      updates - a map of updates
      Returns:
      an immutable result map built from target and updates
    • extractPrefixMap

      public static Map<String,String> extractPrefixMap(Map<String,String> properties, String prefix)
      Takes in a map, and returns a copy filtered on the entries with keys beginning with the designated prefix. The keys are returned with the prefix removed.

      Any entries whose keys don't begin with the prefix are not returned.

      This can be used to get a subset of the configuration related to the REST catalog, such as all properties from a prefix of `spark.sql.catalog.my_catalog.rest.` to get REST catalog specific properties from the spark configuration.

    • encodeFormData

      public static String encodeFormData(Map<?,?> formData)
      Encodes a map of form data as application/x-www-form-urlencoded.

      This encodes the form with pairs separated by & and keys separated from values by =.

      Parameters:
      formData - a map of form data
      Returns:
      a String of encoded form data
    • decodeFormData

      public static Map<String,String> decodeFormData(String formString)
      Decodes a map of form data from application/x-www-form-urlencoded.

      This decodes the form with pairs separated by & and keys separated from values by =.

      Parameters:
      formString - a map of form data
      Returns:
      a map of key/value form data
    • encodeString

      public static String encodeString(String toEncode)
      Encodes a string using application/x-www-form-urlencoded encoding, where spaces are encoded as +.

      This method is suitable for encoding form data (e.g. OAuth2 token requests) but not for URL path segments, where + is a literal character. Use encodePathSegment(String) for path segments.

      decodeString(String) should be used to decode.

      Parameters:
      toEncode - string to encode
      Returns:
      form-encoded string, suitable for use in application/x-www-form-urlencoded content
    • decodeString

      public static String decodeString(String encoded)
      Decodes a string that was encoded using application/x-www-form-urlencoded encoding, where + is decoded as a space.

      This method is suitable for decoding form data but not for URL path segments. Use decodePathSegment(String) for path segments.

      See also encodeString(String) for form encoding.

      Parameters:
      encoded - a string to decode
      Returns:
      a decoded string
    • encodePathSegment

      public static String encodePathSegment(String segment)
      Encodes a string for use as a URL path segment per RFC 3986. Spaces are encoded as %20 (not +), and other non-unreserved characters are percent-encoded.

      decodePathSegment(String) should be used to decode.

      Parameters:
      segment - string to encode
      Returns:
      percent-encoded string suitable for use in URL path segments
    • decodePathSegment

      public static String decodePathSegment(String encoded)
      Decodes a URL path segment per RFC 3986. Unlike decodeString(String), this method does not treat + as a space — it is left as a literal + character.

      See also encodePathSegment(String) for encoding.

      Parameters:
      encoded - a percent-encoded path segment
      Returns:
      a decoded string
    • namespaceToQueryParam

      public static String namespaceToQueryParam(Namespace namespace)
      This converts the given namespace to a string and separates each part in a multipart namespace using the unicode character ''. Note that this method is different from encodeNamespace(Namespace, String), which URL-encodes each part of the namespace.

      namespaceFromQueryParam(String) should be used to convert the namespace string back to a Namespace instance.

      Parameters:
      namespace - The namespace to convert
      Returns:
      The namespace converted to a string where each part in a multipart namespace is separated using the unicode character ''
    • namespaceToQueryParam

      public static String namespaceToQueryParam(Namespace namespace, String unicodeNamespaceSeparator)
      This converts the given namespace to a string and separates each part in a multipart namespace using the provided unicode separator.

      namespaceFromQueryParam(String, String) should be used to convert the namespace string back to a Namespace instance.

      Parameters:
      namespace - The namespace to convert
      unicodeNamespaceSeparator - The unicode namespace separator to use, such as '.'
      Returns:
      The namespace converted to a string where each part in a multipart namespace is separated using the given unicode separator
    • namespaceFromQueryParam

      public static Namespace namespaceFromQueryParam(String namespace)
      This converts a namespace where each part in a multipart namespace has been separated using '' to its original Namespace instance.

      namespaceToQueryParam(Namespace) should be used to convert the Namespace to a string.

      Parameters:
      namespace - The namespace to convert
      Returns:
      The namespace instance from the given namespace string, where each part in a multipart namespace is converted using the unicode separator ''
    • namespaceFromQueryParam

      public static Namespace namespaceFromQueryParam(String namespace, String unicodeNamespaceSeparator)
      This converts a namespace where each part in a multipart namespace has been separated using the provided unicode separator to its original Namespace instance.

      namespaceToQueryParam(Namespace, String) should be used to convert the Namespace to a string.

      Parameters:
      namespace - The namespace to convert
      unicodeNamespaceSeparator - The unicode namespace separator to use, such as '.'
      Returns:
      The namespace instance from the given namespace string, where each part in a multipart namespace is converted using the given unicode namespace separator
    • encodeNamespace

      public static String encodeNamespace(Namespace namespace, String separator)
      Returns a String representation of a namespace that is suitable for use with application/x-www-form-urlencoded encoding.

      This function needs to be called when a namespace is used in a POST request body, to format the namespace per the spec.

      decodeNamespace(String, String) should be used to parse the namespace from a request body.

      Parameters:
      namespace - namespace to encode
      separator - The namespace separator to be used for encoding. The separator will be used as-is and won't be UTF-8 encoded.
      Returns:
      UTF-8 encoded string representing the namespace, suitable for use as a URL parameter
    • decodeNamespace

      public static Namespace decodeNamespace(String encodedNamespace, String separator)
      Takes in a string representation of a namespace encoded with application/x-www-form-urlencoded encoding, and returns the corresponding namespace.

      See also encodeNamespace(org.apache.iceberg.catalog.Namespace, java.lang.String) for generating correctly formatted POST requests.

      Parameters:
      encodedNamespace - a namespace to decode
      separator - The namespace separator to be used as-is for decoding. This should be the same separator that was used when calling encodeNamespace(Namespace, String)
      Returns:
      a namespace
    • encodeNamespaceAsPathSegment

      public static String encodeNamespaceAsPathSegment(Namespace namespace, String separator)
      Returns a String representation of a namespace that is suitable for use in a URL path segment per RFC 3986. Spaces are encoded as %20 (not +).

      This method should be used instead of encodeNamespace(Namespace, String) when the result is placed into a URL path.

      decodeNamespaceAsPathSegment(String, String) should be used to decode the result.

      Parameters:
      namespace - namespace to encode
      separator - The namespace separator to be used for encoding. The separator will be used as-is and won't be encoded.
      Returns:
      percent-encoded string representing the namespace, suitable for use in URL path segments
    • decodeNamespaceAsPathSegment

      public static Namespace decodeNamespaceAsPathSegment(String encodedNamespace, String separator)
      Decodes a URL path segment per RFC 3986 into a namespace. Unlike decodeNamespace(String, String), this method does not treat + as a space.

      encodeNamespaceAsPathSegment(Namespace, String) should be used for encoding path segments.

      Parameters:
      encodedNamespace - a percent-encoded namespace path segment
      separator - The namespace separator used during encoding
      Returns:
      a namespace
    • resolveEndpoint

      public static String resolveEndpoint(String catalogUri, String endpointPath)
      Returns the catalog URI suffixed by the relative endpoint path. If the endpoint path is an absolute path, then the absolute endpoint path is returned without using the catalog URI.
      Parameters:
      catalogUri - The catalog URI that is typically passed through CatalogProperties.URI
      endpointPath - Either an absolute or relative endpoint path
      Returns:
      The actual endpoint path if it's an absolute path or the catalog uri suffixed by the endpoint path if the path is relative.
    • configHeaders

      public static Map<String,String> configHeaders(Map<String,String> properties)
    • idempotencyHeaders

      public static Map<String,String> idempotencyHeaders()
      Returns a single-use headers map containing a freshly generated idempotency key. The key is a UUIDv7 string suitable for use in the Idempotency-Key header.
    • credentialsQueryParams

      public static Map<String,String> credentialsQueryParams(Map<String,String> properties)
      Query parameters for the loadCredentials endpoint, from client-side request context.