Skip to content

Commit 61972ea

Browse files
authored
Drop fivetran_utils by copying code. (#97)
1 parent 382b731 commit 61972ea

6 files changed

Lines changed: 102 additions & 26 deletions

File tree

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ Third party Apache 2.0 licenses
2828
The following files contain signifant parts of code licensed under third party Apache 2.0 License.
2929

3030
macros/public/validating/regex_dict.sql
31+
macros/utils/fivetran_utils/percentile.sql
32+
macros/utils/fivetran_utils/json_extract.sql
3133

3234

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{#
2+
# This file contains significant part of code derived from
3+
# https://github.com/fivetran/dbt_fivetran_utils/tree/v0.4.0 which is licensed under Apache License 2.0.
4+
#}
5+
6+
{% macro json_extract(string, string_path) -%}
7+
8+
{{ adapter.dispatch('json_extract') (string, string_path) }}
9+
10+
{%- endmacro %}
11+
12+
{% macro default__json_extract(string, string_path) %}
13+
14+
json_extract_path_text({{string}}, {{ "'" ~ string_path ~ "'" }} )
15+
16+
{% endmacro %}
17+
18+
{% macro snowflake__json_extract(string, string_path) %}
19+
20+
json_extract_path_text(try_parse_json( {{string}} ), {{ "'" ~ string_path ~ "'" }} )
21+
22+
{% endmacro %}
23+
24+
{% macro redshift__json_extract(string, string_path) %}
25+
26+
case when is_valid_json( {{string}} ) then json_extract_path_text({{string}}, {{ "'" ~ string_path ~ "'" }} ) else null end
27+
28+
{% endmacro %}
29+
30+
{% macro bigquery__json_extract(string, string_path) %}
31+
32+
json_extract_scalar({{string}}, {{ "'$." ~ string_path ~ "'" }} )
33+
34+
{% endmacro %}
35+
36+
{% macro postgres__json_extract(string, string_path) %}
37+
38+
{{string}}::json->>{{"'" ~ string_path ~ "'" }}
39+
40+
{% endmacro %}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{#
2+
# This file contains significant part of code derived from
3+
# https://github.com/fivetran/dbt_fivetran_utils/tree/v0.4.0 which is licensed under Apache License 2.0.
4+
#}
5+
6+
{% macro percentile(percentile_field, partition_field, percent) -%}
7+
8+
{{ adapter.dispatch('percentile') (percentile_field, partition_field, percent) }}
9+
10+
{%- endmacro %}
11+
12+
--percentile calculation specific to Redshift
13+
{% macro default__percentile(percentile_field, partition_field, percent) %}
14+
15+
percentile_cont(
16+
{{ percent }} )
17+
within group ( order by {{ percentile_field }} )
18+
over ( partition by {{ partition_field }} )
19+
20+
{% endmacro %}
21+
22+
--percentile calculation specific to Redshift
23+
{% macro redshift__percentile(percentile_field, partition_field, percent) %}
24+
25+
percentile_cont(
26+
{{ percent }} )
27+
within group ( order by {{ percentile_field }} )
28+
over ( partition by {{ partition_field }} )
29+
30+
{% endmacro %}
31+
32+
--percentile calculation specific to BigQuery
33+
{% macro bigquery__percentile(percentile_field, partition_field, percent) %}
34+
35+
percentile_cont(
36+
{{ percentile_field }},
37+
{{ percent }})
38+
over (partition by {{ partition_field }}
39+
)
40+
41+
{% endmacro %}
42+
43+
{% macro postgres__percentile(percentile_field, partition_field, percent) %}
44+
45+
percentile_cont(
46+
{{ percent }} )
47+
within group ( order by {{ percentile_field }} )
48+
/* have to group by partition field */
49+
50+
{% endmacro %}
51+
52+
{% macro spark__percentile(percentile_field, partition_field, percent) %}
53+
54+
percentile(
55+
{{ percentile_field }},
56+
{{ percent }})
57+
over (partition by {{ partition_field }}
58+
)
59+
60+
{% endmacro %}

macros/utils/json_extract.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

macros/utils/percentile.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
packages:
33
- package: dbt-labs/dbt_utils
44
version: [">=0.7.0", "<0.9.0"]
5-
6-
- package: fivetran/fivetran_utils
7-
version: 0.3.9

0 commit comments

Comments
 (0)