Accepts a UInt32 number. Interprets it as a big-endian IPv4 address. Returns a string containing the corresponding IPv4 address, in the format ABCd (decimal numbers separated by dots).
Syntax:
IPv4NumToString(num)
Parameter:
num – a UInt32 number.Return value:
Example:
SELECT toIPv4('116.106.34.242') as ipv4, toTypeName(ipv4), IPv4NumToString(ipv4) as ipv4_string, toTypeName(ipv4_string)
┌─ipv4───────────┬─toTypeName(toIPv4('116.106.34.242'))─┬─ipv4_string────┬─toTypeName(IPv4NumToString(toIPv4('116.106.34.242')))─┐ │ 242.34.106.116 │ IPv4 │ 116.106.34.242 │ String │ └────────────────┴──────────────────────────────────────┴────────────────┴───────────────────────────────────────────────────────┘
Similar to IPv4NumToString, but uses xxx instead of the last octet.
Syntax:
IPv4NumToStringClassC(num)
Parameter:
num – a UInt32 number.Return value:
Example:
SELECT toIPv4('116.106.34.242') as ipv4, toTypeName(ipv4), IPv4NumToStringClassC(ipv4) as ipv4_string, toTypeName(ipv4_string)
┌─ipv4───────────┬─toTypeName(toIPv4('116.106.34.242'))─┬─ipv4_string────┬─toTypeName(IPv4NumToStringClassC(toIPv4('116.106.34.242')))─┐ │ 242.34.106.116 │ IPv4 │ 116.106.34.xxx │ String │ └────────────────┴──────────────────────────────────────┴────────────────┴─────────────────────────────────────────────────────────────┘
The inverse function of IPv4NumToString. If the IPv4 address format is invalid, returns 0.
Syntax:
IPv4StringToNum(s)
Parameter:
s – IPv4 address represented as a string.Return value:
Example:
SELECT IPv4StringToNum('116.106.34.242') as ipv4, toTypeName(ipv4), IPv4NumToString(ipv4) as ipv4_string, toTypeName(ipv4_string)
┌─ipv4───────┬─toTypeName(IPv4StringToNum('116.106.34.242'))─┬─ipv4_string────┬─toTypeName(IPv4NumToString(IPv4StringToNum('116.106.34.242')))─┐ │ 1953112818 │ UInt32 │ 116.106.34.242 │ String │ └────────────┴───────────────────────────────────────────────┴────────────────┴────────────────────────────────────────────────────────────────┘
Accepts a UInt32 number. Interprets it as a big endian IPv4 address. Returns a FixedString(16) value containing the IPv6 address in binary format.
Syntax:
IPv4ToIPv6(x)
Parameter:
x – a UInt32 numberReturn value:
Example:
SELECT IPv4StringToNum('192.168.0.1') as ipv4, IPv6NumToString(IPv4ToIPv6(ipv4)) as ipv6_string
┌─ipv4───────┬─ipv6_string────────┐ │ 3232235521 │ ::ffff:192.168.0.1 │ └────────────┴────────────────────┘
Accepts a FixedString(16) value containing the IPv6 address in binary format. Returns a string containing the text format of this address.
IPv6-mapped IPv4 addresses are output in the format ::ffff:111.222.33.44.
Syntax:
IPv6NumToString(x)
Parameter:
x – FixedString(16) value containing the IPv6 address in binary formatReturn value:
Example:
SELECT IPv6NumToString(toFixedString(unhex('2A0206B8000000000000000000000011'), 16)) AS addr;
┌─addr─────────┐ │ 2a02:6b8::11 │ └──────────────┘
The inverse function of IPv6NumToString. If the IPv6 address format is invalid, returns an empty byte string.
If the input string contains a valid IPv4 address, returns its IPv6 equivalent value. HEX can be uppercase or lowercase.
Syntax:
IPv6StringToNum(string)
Parameter:
string — IP address. String.Return value:
Example:
SELECT addr, cutIPv6(IPv6StringToNum(addr), 0, 0) FROM (SELECT ['notaddress', '127.0.0.1', '1111::ffff'] AS addr) ARRAY JOIN addr;
┌─addr───────┬─cutIPv6(IPv6StringToNum(addr), 0, 0)─┐ │ notaddress │ :: │ │ 127.0.0.1 │ :: │ │ 1111::ffff │ 1111::ffff │ └────────────┴──────────────────────────────────────┘
Accepts a FixedString(16) value containing the IPv6 address in binary format. Returns a string in text format containing the address with the specified number of bytes deleted.
Syntax:
cutIPv6(x, bytesToCutForIPv6, bytesToCutForIPv4)
Parameter:
x – FixedString(16) value containing the IPv6 address in binary formatbytesToCutForIPv6 – number of bytes to delete for IPv6 representationbytesToCutForIPv4 – number of bytes to delete for IPv4 representationReturn value:
A Uint64 data type hash value.
Type: UInt64
Example:
WITH IPv6StringToNum('2001:0DB8:AC10:FE01:FEED:BABE:CAFE:F00D') AS ipv6, IPv4ToIPv6(IPv4StringToNum('192.168.0.1')) AS ipv4 SELECT cutIPv6(ipv6, 2, 0), cutIPv6(ipv4, 0, 2)
┌─cutIPv6(ipv6, 2, 0)─────────────────┬─cutIPv6(ipv4, 0, 2)─┐ │ 2001:db8:ac10:fe01:feed:babe:cafe:0 │ ::ffff:192.168.0.0 │ └─────────────────────────────────────┴─────────────────────┘
Alias of IPv4StringToNum(). Accepts the string form of an IPv4 address and returns a value of IPv4 type, which is binary and equals the value returned by IPv4StringToNum().
Syntax:
toIPv4(string)
Parameter:
string — IP address. String.Return value:
Example:
WITH'171.225.130.45' as IPv4_string SELECT toTypeName(IPv4StringToNum(IPv4_string)), toTypeName(toIPv4(IPv4_string))
┌─toTypeName(IPv4StringToNum(IPv4_string))─┬─toTypeName(toIPv4(IPv4_string))─┐ │ UInt32 │ IPv4 │ └──────────────────────────────────────────┴─────────────────────────────────┘
WITH'171.225.130.45' as IPv4_string SELECT hex(IPv4StringToNum(IPv4_string)), hex(toIPv4(IPv4_string))
┌─hex(IPv4StringToNum(IPv4_string))─┬─hex(toIPv4(IPv4_string))─┐ │ ABE1822D │ ABE1822D │ └───────────────────────────────────┴──────────────────────────┘
Converts an IPv6 address in string form to IPv6 type. If the IPv6 address format is invalid, then return null.
Similar to the IPv6StringToNum function, converts the IPv6 address to binary format.
Syntax
toIPv6(string)
Arguments
string— IP address. StringReturn value
Example
WITH '2001:438:ffff::407d:1bc1' AS IPv6_string SELECT hex(IPv6StringToNum(IPv6_string)), hex(toIPv6(IPv6_string));
┌─hex(IPv6StringToNum(IPv6_string))─┬─hex(toIPv6(IPv6_string))─────────┐ │ 20010438FFFF000000000000407D1BC1 │ 20010438FFFF000000000000407D1BC1 │ └───────────────────────────────────┴──────────────────────────────────┘
Returns an array that contains the URL, truncated at the end of the path and query string by the symbols /,?. Truncation. Consecutive delimiters are counted as one. Truncation is carried out at the location after all consecutive delimiters.
Syntax
URLHierarchy(URL)
Arguments
URL— URL。 Type: String.Return value
Example
SELECT URLHierarchy('https://example.com/browse/CONV-6788');
┌─URLHierarchy('https://example.com/browse/CONV-6788')────────────────────────────────────────────┐ │ ['https://example.com/', 'https://example.com/browse/', 'https://example.com/browse/CONV-6788'] │ └─────────────────────────────────────────────────────────────────────────────────────────────────┘
Same as above, but the result does not include protocol and host. Does not include the / element (root).
Syntax
URLPathHierarchy(URL)
Arguments
URL— URL。 Type: String.Return value
Example
SELECT URLPathHierarchy('https://example.com/browse/CONV-6788');
┌─URLPathHierarchy('https://example.com/browse/CONV-6788')─┐ │ ['/browse/', '/browse/CONV-6788'] │ └──────────────────────────────────────────────────────────┘
Delete the fragment identifier. The number sign is also deleted.
Syntax
cutFragment(URL)
Arguments
URL– URL stringReturn value
Example
SELECT cutFragment('http://example.com#fragment')
┌─cutFragment('http://example.com#fragment')─┐ │ http://example.com │ └────────────────────────────────────────────┘
Delete the query string. The question mark is also deleted.
Syntax
cutQueryString(URL)
Arguments
URL– URL stringReturn value
Example
SELECT cutQueryString('http://example.com/?page=1&lr=213')
┌─cutQueryString('http://example.com/?page=1&lr=213')─┐ │ http://example.com/ │ └─────────────────────────────────────────────────────┘
Delete the query string and fragment identifier. The question mark and number sign are also deleted.
Syntax
cutQueryStringAndFragment(URL)
Arguments
URL– URL stringReturn value
Example
SELECT cutQueryStringAndFragment('http://example.com/?page=1&lr=213#fragment')
┌─cutQueryStringAndFragment('http://example.com/?page=1&lr=213#fragment')─┐ │ http://example.com/ │ └─────────────────────────────────────────────────────────────────────────┘
Returns the domain name part that contains the top-level subdomain up to the "first significant subdomain".
Syntax
cutToFirstSignificantSubdomain(URL)
Arguments
URL– URL stringReturn value
Example
SELECT cutToFirstSignificantSubdomain('https://www.example.com.cn/')
┌─cutToFirstSignificantSubdomain('https://www.example.com.cn/')─┐ │ example.com.cn │ └───────────────────────────────────────────────────────────────┘
Delete the "name" URL parameter (if present). This function works under the assumption that the encoding method of the parameter name in the URL is exactly the same as the encoding method of the parameter passed in.
Syntax
cutURLParameter(URL, name)
Arguments
URL– URL stringnameParameter nameReturn value
Example
SELECT cutURLParameter('http://example.com/?page=1&lr=213','page')
┌─cutURLParameter('http://example.com/?page=1&lr=213', 'page')─┐ │ http://example.com/?lr=213 │ └──────────────────────────────────────────────────────────────┘
If present, delete at most one "www." from the beginning of the URL domain name.
Syntax
cutWWW(URL)
Arguments
URL– URL stringnameParameter nameReturn value
Example
SELECT cutWWW('http://www.example.com/?page=1&lr=213')
┌─cutWWW('http://www.example.com/?page=1&lr=213')─┐ │ http://example.com/?page=1&lr=213 │ └─────────────────────────────────────────────────┘
Returns the decoded URL.
Syntax
decodeURLComponent(URL)
Arguments
URL– URL stringReturn value
Example
SELECT decodeURLComponent('http://127.0.0.1:8123/?query=SELECT%201%3B') AS DecodedURL;
┌─DecodedURL─────────────────────────────┐ │ http://127.0.0.1:8123/?query=SELECT 1; │ └────────────────────────────────────────┘
Extracts the hostname from the URL.
Syntax
domain(url)
Arguments
url— URL。 Type: String. URLThe scheme can be specified or not specified. Example:
svn+ssh://some.svn-hosting.com:80/repo/trunk some.svn-hosting.com:80/repo/trunk https://yandex.com/time/
For these examples, the domain function returns the following results:
some.svn-hosting.com some.svn-hosting.com yandex.com
Return value
Type: String.
Example
SELECT domain('svn+ssh://some.svn-hosting.com:80/repo/trunk');
┌─domain('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐ │ some.svn-hosting.com │ └────────────────────────────────────────────────────────┘
Returns the domain name and removes at most one leading "www." (if present).
Syntax
domainWithoutWWW(url)
Parameter
url— URL。 Type: String.Return value
Type: String.
Example
SELECT domainWithoutWWW('http://www.example.com#fragment');
┌─domainWithoutWWW('http://www.example.com#fragment')─┐ │ example.com │ └─────────────────────────────────────────────────────┘
Returns the value of the "name" Param in the URL (if present). Otherwise, returns an empty string. If there are multiple Params with the same Parameter name, returns the first one. This function works under the assumption that the encoding method of the Parameter name in the URL is exactly the same as the encoding method in the provided Param.
Syntax
extractURLParameter(URL, name)
Parameter
URL– URL stringname Parameter nameReturn value
Example
SELECT extractURLParameter('http://example.com/?page=1&lr=213','page')
┌─extractURLParameter('http://example.com/?page=1&lr=213', 'page')─┐ │ 1 │ └──────────────────────────────────────────────────────────────────┘
Returns a string array of names corresponding to the Parameter names in the URL. The value is not decoded in any way.
Syntax
extractURLParameterNames(URL)
Parameter
URL– URL stringReturn value
Example
SELECT extractURLParameterNames('http://example.com/?page=1&lr=213')
┌─extractURLParameterNames('http://example.com/?page=1&lr=213')─┐ │ ['page', 'lr'] │ └───────────────────────────────────────────────────────────────┘
Returns a string array of name=value pairs corresponding to the Params in the URL. These values are not decoded in any way.
Syntax
extractURLParameters(URL)
Parameter
URL– URL stringReturn value
Example
SELECT extractURLParameters('http://example.com/?page=1&lr=213')
┌─extractURLParameters('http://example.com/?page=1&lr=213')─┐ │ ['page=1', 'lr=213'] │ └───────────────────────────────────────────────────────────┘
Returns the "first significant subdomain". This is a non-standard concept specific to Yandex.Metrica. If the first significant subdomain is "com", "net", "org", or "co", then it is a second-level domain name. Otherwise, it is a third-level domain name.
Syntax
firstSignificantSubdomain(URL)
Parameter
URL– URL stringReturn value
Example
SELECT firstSignificantSubdomain('https://www.example.com.cn/')
┌─firstSignificantSubdomain('https://www.example.com.cn/')─┐ │ example │ └──────────────────────────────────────────────────────────┘
Returns the fragment identifier. The fragment does not include the initial hash sign.
Syntax
fragment(URL)
Parameter
URL– URL stringReturn value
Example
SELECT fragment('http://example.com#fragment')
┌─fragment('http://example.com#fragment')─┐ │ fragment │ └─────────────────────────────────────────┘
Returns the path. Example: /top/news.html The path does not include the query string.
Syntax
path(URL)
Parameter
URL– URL stringReturn value
Example
SELECT path('http://example.com/top/news.html')
┌─path('http://example.com/top/news.html')─┐ │ /top/news.html │ └──────────────────────────────────────────┘
Extracts the protocol from the URL.
Typical return value examples: http, https, ftp, mailto, tel, magnet…
Syntax
protocol(URL)
Parameter
URL– URL stringReturn value
Example
SELECT protocol('http://example.com')
┌─protocol('http://example.com')─┐ │ http │ └────────────────────────────────┘
Returns the query string. Example: page=1&lr=213. The query string does not include the initial question mark, #, or anything after the #.
Syntax
queryString(URL)
Parameter
URL– URL stringReturn value
Example
SELECT queryString('http://example.com/?page=1&lr=213')
┌─queryString('http://example.com/?page=1&lr=213')─┐ │ page=1&lr=213 │ └──────────────────────────────────────────────────┘
Returns the query string and fragment identifier. Example: page=1#29390.
Syntax
queryStringAndFragment(URL)
Parameter
URL– URL stringReturn value
Example
SELECT queryStringAndFragment('http://example.com/?page=1&lr=213#fragment')
┌─queryStringAndFragment('http://example.com/?page=1&lr=213#fragment')─┐ │ page=1&lr=213#fragment │ └──────────────────────────────────────────────────────────────────────┘
Extract the top-level domain from a URL.
Syntax
topLevelDomain(url)
Param
url— URL。 Type: String. URLThe scheme can be specified or omitted. Example:
svn+ssh://some.svn-hosting.com:80/repo/trunk some.svn-hosting.com:80/repo/trunk https://yandex.com/time/
Return value
Type: String.
Example
SELECT topLevelDomain('svn+ssh://www.some.svn-hosting.com:80/repo/trunk');
┌─topLevelDomain('svn+ssh://www.some.svn-hosting.com:80/repo/trunk')─┐ │ com │ └────────────────────────────────────────────────────────────────────┘