All Products
Search
Document Center

MaxCompute:PARSE_URL

Last Updated:Jul 24, 2023

Parses url and extracts information based on the value specified by part.

Syntax

string parse_url(string <url>, string <part>[, string <key>])

Parameters

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

  • part: required. A value of the STRING type. Valid values: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. The value of this parameter is not case-sensitive.

  • key: optional. If part is set to QUERY, this function returns the value that corresponds to key.

Return value

A value of the STRING type is returned. The return value varies based on the following rules:

  • If the value of url, part, or key is null, null is returned.

  • If the value of part is invalid, an error is returned.

Examples

-- The return value is example.com. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'HOST');
-- The return value is /over/there/index.dtb. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'PATH');
-- The return value is animal. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'QUERY', 'type');
-- The return value is nose. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'REF');
-- The return value is file. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'PROTOCOL');
-- The return value is username:password@example.com:8042. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'AUTHORITY');
-- The return value is username:password. 
select parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'USERINFO');

Related functions

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