二十、 clickhouse的URL函數


所有這些功能都不遵循RFC。它們被最大程度簡化以提高性能。
--- 什么事RFC?
---- Request For Comments(RFC),是一系列以編號排定的文件。文件收集了有關互聯網相關信息,以及UNIX和互聯網社區的軟件文件。

一、提取部分 URL 的函數 

如果 URL 中不存在相關部分,則返回一個空字符串。

--1.protocol

--從 URL 中提取協議。

典型返回值示例:http、https、ftp、mailto、tel、magnet……

示例

SELECT protocol('svn+ssh://some.svn-hosting.com:80/repo/trunk')

Query id: bec1936f-eb94-4223-aef2-d4e7af1e5ea4

┌─protocol('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ svn+ssh                                                  │
└──────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--2.omain

--從 URL 中提取主機名。

domain(url)

論據

  • url— 網址。類型:字符串

可以使用或不使用方案來指定 URL。例子:

svn+ssh://some.svn-hosting.com:80/repo/trunk
some.svn-hosting.com:80/repo/trunk
https://yandex.com/time/

對於這些示例,該domain函數返回以下結果:

some.svn-hosting.com
some.svn-hosting.com
yandex.com

返回值

  • 地址名。如果 ClickHouse 可以將輸入字符串解析為 URL。
  • 空字符串。如果 ClickHouse 無法將輸入字符串解析為 URL。

類型:String.

例子

SELECT domain('svn+ssh://some.svn-hosting.com:80/repo/trunk')

Query id: 6e1ae2c1-7b44-4634-a4a8-cc44340f4b24

┌─domain('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ some.svn-hosting.com                                   │
└────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--3.domainWithoutWWW 

--返回域並刪除不超過一個“ www”。從一開始,如果存在的話。

示例

SELECT domainWithoutWWW('svn+ssh://some.svn-hosting.com:80/repo/trunk')

Query id: 741ab740-fc0f-426c-af1d-ca2f0e35bb00

┌─domainWithoutWWW('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ some.svn-hosting.com                                             │
└──────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--4.topLevelDomain 

--從 URL 中提取頂級域。

topLevelDomain(url)

論據

  • url— 網址。類型:字符串

可以使用或不使用方案來指定 URL。例子:

svn+ssh://some.svn-hosting.com:80/repo/trunk
some.svn-hosting.com:80/repo/trunk
https://yandex.com/time/

返回值

  • 域名。如果 ClickHouse 可以將輸入字符串解析為 URL。
  • 空字符串。如果 ClickHouse 無法將輸入字符串解析為 URL。

類型:String.

例子

SELECT topLevelDomain('svn+ssh://some.svn-hosting.com:80/repo/trunk')

Query id: 8c5354f4-a378-4726-b4ca-83ce313a4ade

┌─topLevelDomain('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ com                                                            │
└────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--5.firstSignificantSubdomain 

--返回“第一個重要子域”。這是 Yandex.Metrica 特有的非標准概念。如果第一個重要子域是“com”、“net”、“org”或“co”,則它是二級域。否則為三級域。

例如

SELECT firstSignificantSubdomain('https://news.yandex.com.tr/')

Query id: 1e12f972-9589-464d-901e-2d46713a49d8

┌─firstSignificantSubdomain('https://news.yandex.com.tr/')─┐
│ yandex                                                   │
└──────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

“無關緊要的”二級域列表和其他實現細節可能會在未來發生變化。

--6.cutToFirstSignificantSubdomain 

--返回包含頂級子域的域部分,直到“第一個重要子域”(參見上面的解釋)。

SELECT cutToFirstSignificantSubdomain('https://news.yandex.com.tr/')

Query id: a50baf0a-09c9-4efc-b3fd-c2884f10b7c2

┌─cutToFirstSignificantSubdomain('https://news.yandex.com.tr/')─┐
│ yandex.com.tr                                                 │
└───────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec.

 

--7.cutToFirstSignificantSubdomainWithWWW

--返回包含頂級子域的域部分,直到“第一個重要子域”,而不剝離“www”。

例如:

SELECT cutToFirstSignificantSubdomain('https://news.yandex.com.tr/')

Query id: e8bd3231-4b5d-4414-92de-c78bd7efbcb5

┌─cutToFirstSignificantSubdomain('https://news.yandex.com.tr/')─┐
│ yandex.com.tr                                                 │
└───────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--8.cutToFirstSignificantSubdomainCustom

--返回包含頂級子域到第一個重要子域的域部分。接受自定義TLD 列表名稱。

如果您需要新的 TLD 列表或者您有自定義,這可能會很有用。

配置示例:

<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>

 

句法

cutToFirstSignificantSubdomain(URL, TLD)

參數

  • URL— 網址。字符串
  • TLD— 自定義 TLD 列表名稱。字符串

返回值

  • 包含頂級子域到第一個重要子域的域的一部分。

類型:字符串

例子

SELECT cutToFirstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list');

┌─cutToFirstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list')─┐
│ foo.there-is-no-such-domain                                                                   │
└───────────────────────────────────────────────────────────────────────────────────────────────┘

 

也可以看看

  • 第一個重要子域

--9.cutToFirstSignificantSubdomainCustomWithWWW

--返回包含頂級子域的域部分,直到第一個重要子域而不剝離www接受自定義 TLD 列表名稱。

如果您需要新的 TLD 列表或者您有自定義,這可能會很有用。

配置示例:

<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>

 

句法

cutToFirstSignificantSubdomainCustomWithWWW(URL, TLD)

參數

  • URL— 網址。字符串
  • TLD— 自定義 TLD 列表名稱。字符串

返回值

  • 包含頂級子域的域的一部分,直到第一個重要子域,沒有剝離www

類型:字符串

例子

SELECT cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list');

┌─cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list')─┐
│ www.foo                                                                      │
└──────────────────────────────────────────────────────────────────────────────┘

 

也可以看看

  • 第一個重要子域

--10.firstSignificantSubdomainCustom {

--返回第一個重要的子域。接受TLD 列表名稱。

如果您需要新的 TLD 列表或者您有自定義,這可能會很有用。

配置示例:

<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>

 

句法

firstSignificantSubdomainCustom(URL, TLD)

參數

  • URL— 網址。字符串
  • TLD— 自定義 TLD 列表名稱。字符串

返回值

  • 第一個重要子域。

類型:字符串

例子

詢問:

SELECT firstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list');

┌─firstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list')─┐
│ foo                                                                                      │
└──────────────────────────────────────────────────────────────────────────────────────────┘

 

也可以看看

  • 第一個重要子域

--11.port(URL[,default_port = 0])

--返回端口或者default_port如果 URL 中沒有端口(或在驗證錯誤的情況下)。

--12.path 

--返回路徑。路徑不包含查詢字符串。

--13.pathFull 

--同上,但包括查詢字符串和片段。

--14.queryString 

--返回查詢字符串。查詢字符串不包括最初的問號,以及 # 和 # 之后的所有內容。

--15.fragment

--返回片段標識符。片段不包括初始哈希符號。

--16.queryStringAndFragment 

--返回查詢字符串和片段標識符。

--17.extractURLParameter(URL, name) 

-返回 URL 中的 'name' 參數的值(如果存在)。否則為空字符串。如果有許多具有此名稱的參數,則返回第一個出現的參數。此函數的工作假設參數名稱在 URL 中的編碼方式與在傳遞參數中的編碼方式完全相同。

--18.extractURLParameters(URL)

--返回與 URL 參數對應的 name=value 字符串數組。這些值不會以任何方式解碼。

--19.extractURLParameterNames(URL) 

--返回與 URL 參數名稱對應的名稱字符串數組。這些值不會以任何方式解碼。

--20.URLHierarchy(URL)

--返回一個包含 URL 的數組,在末尾被符號 /,? 截斷 在路徑和查詢字符串中。連續的分隔符算作一個。在所有連續分隔符之后的位置進行剪切。

示例

SELECT
    port('http://paul@www.example.com:80/'),
    path('https://blog.csdn.net/u012111465/article/details/85250030'),
    pathFull('https://clickhouse.yandex/#quick-start'),
    queryString('http://paul@www.example.com:80/page=1&lr=213'),
    fragment('https://clickhouse.yandex/#quick-start'),
    queryStringAndFragment('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai'),
    extractURLParameter('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai', 'ie'),
    extractURLParameters('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai'),
    extractURLParameterNames('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai')

Query id: 554171c6-86fc-4ab5-9b5d-1bb44b6f24a4

┌─port('..')─┬─path('..')─┬─pathFull('..')─┬─queryString('http://paul@www.example.com:80/page=1&lr=213')─┬─fragment('https://clickhouse.yandex/#quick-start')─┬─queryStringAndFragment('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai')─┬─extractURLParameter('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai', 'ie')─┬─extractURLParameters('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai')─┬─extractURLParameterNames('https://www.baidu.com/s?ie=utf-8&rsv_sug7=100#ei-ai')─┐
│                                      80/u012111465/article/details/85250030/#quick-start                                      │                                                             │ quick-start                                        │ ie=utf-8&rsv_sug7=100#ei-ai                                                   │ utf-8['ie=utf-8','rsv_sug7=100']['ie','rsv_sug7']                                                               │
└─────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.003 sec. 

 

--21.URLPathHierarchy(URL)

--與上面相同,但結果中沒有協議和主機。/ 元素(根)不包括在內。示例:該函數用於在 Yandex 中實現樹形報告 URL。公制。

示例

SELECT URLPathHierarchy('https://example.com/browse/CONV-6788')

Query id: f9f424a8-d9e6-4617-8dac-248ccc1b0d2e

┌─URLPathHierarchy('https://example.com/browse/CONV-6788')─┐
│ ['/browse/','/browse/CONV-6788']                         │
└──────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.004 sec. 
 

--22.decodeURLComponent(URL) 

--返回解碼后的 URL。例子:

SELECT decodeURLComponent('http://127.0.0.1:8123/?query=SELECT%201%3B') AS DecodedURL

Query id: d6b4cefd-3315-4362-b7b6-fe2b48b94053

┌─DecodedURL─────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1; │
└────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--23.decodeURLFormComponent(URL) 

--返回解碼后的 URL。遵循 rfc-1866,普通的 plus( +) 被解碼為 space( )。例子:

SELECT decodeURLFormComponent('http://127.0.0.1:8123/?query=SELECT%201+2%2B3') AS DecodedURL

Query id: e42a9720-73ec-4f95-ac19-48aef5e83e90

┌─DecodedURL────────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1 2+3 │
└───────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

--24.netloc

username:password@host:port從 URL 中提取網絡位置 ( )。

句法

netloc(URL)

論據

  • url— 網址。字符串

返回值

  • username:password@host:port.

類型:String.

例子

SELECT netloc('http://paul@www.example.com:80/')

Query id: 38bd3547-1461-463c-ab27-63d993ebbba3

┌─netloc('http://paul@www.example.com:80/')─┐
│ paul@www.example.com:80                   │
└───────────────────────────────────────────┘

1 rows in set. Elapsed: 0.002 sec. 

 

二、刪除部分 URL 的函數 

如果 URL 沒有任何類似內容,則 URL 保持不變。

--1.cutWWW 

刪除不超過一個“ www”。從 URL 域的開頭(如果存在)。

--2.cutQueryString 

刪除查詢字符串。問號也被刪除。

--3.cutFragment 

刪除片段標識符。數字符號也被刪除。

--4.cutQueryStringAndFragment 

刪除查詢字符串和片段標識符。問號和數字符號也被刪除。

--5.cutURLParameter(URL, name)

刪除“名稱”URL 參數(如果存在)。此函數的工作假設參數名稱在 URL 中的編碼方式與在傳遞參數中的編碼方式完全相同。

示例

SELECT
    cutWWW('https://www.baidu.com'),
    cutQueryString('http://www.baidu.com/1?page=1'),
    cutFragment('http://www.baidu.com/#quick-demo'),
    cutQueryStringAndFragment('http://www.baidu.com/1?page=23#we'),
    cutURLParameter('http://www.baidu.com/1?page=1#erre&resv=23&name=user', 'resv')

Query id: e55b7a13-3e28-41c8-8079-3d5b86e57a61

┌─cutWWW('https://www.baidu.com')─┬─cutQueryString('http://www.baidu.com/1?page=1')─┬─cutFragment('http://www.baidu.com/#quick-demo')─┬─cutQueryStringAndFragment('http://www.baidu.com/1?page=23#we')─┬─cutURLParameter('http://www.baidu.com/1?page=1#erre&resv=23&name=user', 'resv')─┐
│ https://baidu.com               │ http://www.baidu.com/1                          │ http://www.baidu.com/                           │ http://www.baidu.com/1                                         │ http://www.baidu.com/1?page=1#erre&name=user                                    │
└─────────────────────────────────┴─────────────────────────────────────────────────┴─────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.003 sec. 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM