forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_url_path.sql
34 lines (28 loc) · 877 Bytes
/
get_url_path.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
{% macro get_url_path(field) -%}
{{ return(adapter.dispatch('get_url_path', 'dbt_utils')(field)) }}
{% endmacro %}
{% macro default__get_url_path(field) -%}
{%- set stripped_url =
dbt_utils.replace(
dbt_utils.replace(field, "'http://'", "''"), "'https://'", "''")
-%}
{%- set first_slash_pos -%}
coalesce(
nullif({{dbt_utils.position("'/'", stripped_url)}}, 0),
{{dbt_utils.position("'?'", stripped_url)}} - 1
)
{%- endset -%}
{%- set parsed_path =
dbt_utils.split_part(
dbt_utils.right(
stripped_url,
dbt_utils.length(stripped_url) ~ "-" ~ first_slash_pos
),
"'?'", 1
)
-%}
{{ dbt_utils.safe_cast(
parsed_path,
dbt_utils.type_string()
)}}
{%- endmacro %}