-
Notifications
You must be signed in to change notification settings - Fork 41
/
percentile.sql
60 lines (42 loc) · 1.66 KB
/
percentile.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{#
# This file contains significant part of code derived from
# https://github.com/fivetran/dbt_fivetran_utils/tree/v0.4.0 which is licensed under Apache License 2.0.
#}
{% macro percentile(percentile_field, partition_field, percent) -%}
{{ adapter.dispatch('percentile','re_data') (percentile_field, partition_field, percent) }}
{%- endmacro %}
--percentile calculation specific to Redshift
{% macro default__percentile(percentile_field, partition_field, percent) %}
percentile_cont(
{{ percent }} )
within group ( order by {{ percentile_field }} )
over ( partition by {{ partition_field }} )
{% endmacro %}
--percentile calculation specific to Redshift
{% macro redshift__percentile(percentile_field, partition_field, percent) %}
percentile_cont(
{{ percent }} )
within group ( order by {{ percentile_field }} )
over ( partition by {{ partition_field }} )
{% endmacro %}
--percentile calculation specific to BigQuery
{% macro bigquery__percentile(percentile_field, partition_field, percent) %}
percentile_cont(
{{ percentile_field }},
{{ percent }})
over (partition by {{ partition_field }}
)
{% endmacro %}
{% macro postgres__percentile(percentile_field, partition_field, percent) %}
percentile_cont(
{{ percent }} )
within group ( order by {{ percentile_field }} )
/* have to group by partition field */
{% endmacro %}
{% macro spark__percentile(percentile_field, partition_field, percent) %}
percentile(
{{ percentile_field }},
{{ percent }})
over (partition by {{ partition_field }}
)
{% endmacro %}