-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse_url.sql
44 lines (35 loc) · 1.07 KB
/
parse_url.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- INCLUDE DESCRIPTION HERE TO DESCRIBE MACRO FILE --
-- INCLUDE DESCRIPTION HERE TO DESCRIBE SPECIFIC MACRO --
{%- macro extract_hostname_from_url(url) -%}
REGEXP_EXTRACT(
{{ url }},
'(?:http[s]?://)?(?:www\\.)?(.*?)(?:(?:/|:)(?:.)*|$)'
)
{%- endmacro -%}
-- INCLUDE DESCRIPTION HERE TO DESCRIBE SPECIFIC MACRO --
{%- macro extract_query_string_from_url(url) -%}
REGEXP_EXTRACT(
{{ url }},
'\\?(.+)'
)
{%- endmacro -%}
-- INCLUDE DESCRIPTION HERE TO DESCRIBE SPECIFIC MACRO --
{%- macro remove_query_parameters(url, parameters) -%}
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
{{ url }},
'(\\?|&)({{ parameters|join("|") }})=[^&]*',
'\\1'
),
'\\?&+',
'?'
),
'&+',
'&'
),
'\\?$|&$',
''
)
{%- endmacro -%}