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 %}
0 commit comments