This topic describes the syntax of URL functions. This topic also provides examples on how to use the functions.
The following table describes the URL functions that are supported by Simple Log Service.
The format of a URL is
[protocol:][//host[:port]][path][?query][#fragment]
.If you want to use strings in analytic statements, you must enclose the strings in single quotation marks (''). Strings that are not enclosed or strings that are enclosed in double quotation marks ("") indicate field names or column names. For example, 'status' indicates the status string, and status or "status" indicates the status log field.
Function | Syntax | Description | Supported in SQL | Supported in 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 the value of a specified parameter in the query string from a URL. | √ | √ | |
url_extract_path(x) | Extracts the path from a URL. | √ | √ | |
url_extract_port(x) | Extracts the port number 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
The url_encode function encodes a URL.
Syntax
url_encode(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Encode the value of the url field.
Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
Query statement
* | select url_encode(url)
Query and analysis results
url_decode function
The url_decode function decodes a URL.
Syntax
url_decode(x)
Parameters
Parameter | Description |
x | The value of this parameter is an encoded URL. |
Return value type
The varchar type.
Examples
Decode the value of the url field.
Sample field
url:http%3A%2F%2Fwww.aliyun.com%3A80%2Fproduct%2Fsls
Query statement
* | SELECT url_decode(url) AS decode
Query and analysis results
url_extract_fragment function
The url_extract_fragment function extracts the fragment from a URL.
Syntax
url_extract_fragment(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the fragment from the value of the url field.
Sample field
url:https://sls.console.aliyun.com/#/project/dashboard-demo/categoryList
Query statement
* | SELECT url_extract_fragment(url)
Query and analysis results
url_extract_host function
The url_extract_host function extracts the host from a URL.
Syntax
url_extract_host(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the host from the value of the url field.
Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
Query statement
* | SELECT url_extract_host(url) AS host
Query and analysis results
url_extract_parameter function
The url_extract_parameter function extracts the value of a specified parameter in the query string from a URL.
Syntax
url_extract_parameter(x, parameter name)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
parameter name | The name of the parameter that you want to query in the query string of the URL. |
Return value type
The varchar type.
Examples
Extract the value of the accounttraceid parameter from the value of the url field.
Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
Query statement
* | SELECT url_extract_parameter(url,'accounttraceid') AS accounttraceid
Query and analysis results
url_extract_path function
The url_extract_path function extracts the path from a URL.
Syntax
url_extract_path(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the path from the value of the url field.
Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
Query statement
* | SELECT url_extract_path(url) AS path
Query and analysis results
url_extract_port function
The url_extract_port function extracts the port number from a URL.
Syntax
url_extract_port(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the port number from the value of the url field.
Sample field
url:http://localhost:8080/lognext/profile
Query statement
* | SELECT url_extract_port(url) AS port
Query and analysis results
url_extract_protocol function
The url_extract_protocol function extracts the protocol from a URL.
Syntax
url_extract_protocol(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the protocol from the value of the url field.
Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
Query statement
* | SELECT url_extract_protocol(url) AS protocol
Query and analysis results
url_extract_query function
The url_extract_query function extracts the query string from a URL.
Syntax
url_extract_query(x)
Parameters
Parameter | Description |
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the query string from the value of the url field.
Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
Query statement
* | SELECT url_extract_query(url)
Query and analysis results