Use URL functions to encode, decode, and extract components from URLs in SLS analytic statements.
SLS supports the following URL functions.
-
The URL format is
[protocol:][//host[:port]][path][?query][#fragment]. -
In SLS analytic statements, enclose strings in single quotation marks (''). Unquoted or double-quoted ("") text represents field or column names. For example, 'status' represents the string status, while status or "status" represents the log field named status.
|
Function name |
Syntax |
Description |
SQL |
SPL |
|
url_encode(x) |
Encodes a URL. |
√ |
√ |
|
|
url_decode(x) |
Decodes a URL. |
√ |
√ |
|
|
url_extract_fragment(x) |
Extracts the fragment from a URL. |
√ |
√ |
|
|
url_extract_host(x) |
Extracts the host from a URL. |
√ |
√ |
|
|
url_extract_parameter(x, parameter name) |
Extracts a query parameter value from a URL. |
√ |
√ |
|
|
url_extract_path(x) |
Extracts the path from a URL. |
√ |
√ |
|
|
url_extract_port(x) |
Extracts the port from a URL. |
√ |
√ |
|
|
url_extract_protocol(x) |
Extracts the protocol from a URL. |
√ |
√ |
|
|
url_extract_query(x) |
Extracts the query string from a URL. |
√ |
√ |
url_encode function
Encodes a URL.
Syntax
url_encode(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Encode the url field.
-
Sample log
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService -
Query
* | select url_encode(url) -
Result

url_decode function
Decodes a URL.
Syntax
url_decode(x)
Parameters
|
Parameter |
Description |
|
x |
An encoded URL. |
Return value type
varchar
Examples
Decode the url field.
-
Sample log
url:http%3A%2F%2Fwww.aliyun.com%3A80%2Fproduct%2Fsls -
Query
* | SELECT url_decode(url) AS decode -
Result

url_extract_fragment function
Extracts the fragment from a URL.
Syntax
url_extract_fragment(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the fragment from the url field.
-
Sample log
url:https://sls.console.aliyun.com/#/project/dashboard-demo/categoryList -
Query
* | SELECT url_extract_fragment(url) -
Result

url_extract_host function
Extracts the host from a URL.
Syntax
url_extract_host(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the host from the url field.
-
Sample log
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService -
Query
* | SELECT url_extract_host(url) AS host -
Result

url_extract_parameter function
Extracts a specified query parameter value from a URL.
Syntax
url_extract_parameter(x, parameter name)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
|
parameter name |
The query parameter name. |
Return value type
varchar
Examples
Extract the accounttraceid parameter from the url field.
-
Sample log
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw -
Query
* | SELECT url_extract_parameter(url,'accounttraceid') AS accounttraceid -
Result

url_extract_path function
Extracts the path from a URL.
Syntax
url_extract_path(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the path from the url field.
-
Sample log
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw -
Query
* | SELECT url_extract_path(url) AS path -
Result

url_extract_port function
Extracts the port from a URL.
Syntax
url_extract_port(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the port from the url field.
-
Sample log
url:http://localhost:8080/lognext/profile -
Query
* | SELECT url_extract_port(url) AS port -
Result

url_extract_protocol function
Extracts the protocol from a URL.
Syntax
url_extract_protocol(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the protocol from the url field.
-
Sample log
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService -
Query
* | SELECT url_extract_protocol(url) AS protocol -
Result

url_extract_query function
Extracts the query string from a URL.
Syntax
url_extract_query(x)
Parameters
|
Parameter |
Description |
|
x |
A URL. |
Return value type
varchar
Examples
Extract the query string from the url field.
-
Sample log
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw -
Query
* | SELECT url_extract_query(url) -
Result




