All Products
Search
Document Center

MaxCompute:PARSE_URL_TUPLE

Last Updated:Jul 24, 2023

Parses url and extracts the strings that are specified by a group of input keys, such as key1 and key2.

Usage notes

The PARSE_URL_TUPLE function is similar to the PARSE_URL function. However, the PARSE_URL_TUPLE function provides better performance because it can extract the strings that correspond to multiple keys at the same time.

Syntax

string parse_url_tuple(string <url>, string <key1>, string <key2>,...)

Parameters

  • url: required. A value of the STRING type. This parameter specifies a URL. If the URL is invalid, an error is returned.

  • key1 and key2: required. A value of the STRING type. These parameters specify the keys that correspond to the strings you want to extract. Valid values:

    • HOST: indicates the host address, which can be a domain name or an IP address.

    • PATH: indicates the path of network resources in the server.

    • QUERY: indicates the string that you want to query.

    • REF: indicates the URL annotation, which is displayed when you move your pointer over the URL.

    • PROTOCOL: indicates the protocol type.

    • AUTHORITY: indicates the domain name or IP address, port number, and user authentication information, such as username and password, of the server.

    • FILE: indicates the path of network resources in the server and the content that you want to query. FILE consists of PATH and QUERY.

    • USERINFO: indicates user authentication information.

    • QUERY:<KEY>: indicates the value of the specified key in the query string.

    The values of these parameters are not case-sensitive. If you specify a value other than the preceding values, an error is returned.

Return value

A value of the STRING type is returned. If the value of url or key is null, an error is returned.

Examples

Extract the strings that correspond to keys from file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose. Sample statement:

select parse_url_tuple('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'HOST', 'PATH', 'QUERY', 'REF', 'PROTOCOL', 'AUTHORITY', 'FILE', 'USERINFO', 'QUERY:type', 'QUERY:name') as (item0, item1, item2, item3, item4, item5, item6, item7, item8, item9);

The following result is returned:

+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+
| item0      | item1      | item2      | item3      | item4      | item5      | item6      | item7      | item8      | item9      |
+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+
| example.com | /over/there/index.dtb | type=animal&name=narwhal | nose       | file       | username:password@example.com:8042 | /over/there/index.dtb?type=animal&name=narwhal | username:password | animal     | narwhal    |
+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+

Related functions

PARSE_URL_TUPLE is a string function. For more information about functions related to string searches and conversion, see String functions.