-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_agg.sql
25 lines (20 loc) · 1.36 KB
/
array_agg.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
{% macro array_agg(field, distinct=false, order_field=none, order=none) %}
{{ return(adapter.dispatch("array_agg", macro_namespace="dbt_graph_theory")(field, distinct, order_field, order)) }}
{% endmacro %}
{% macro snowflake__array_agg(field, distinct, order_field, order) %}
array_agg({{ "distinct" if distinct }} {{ field }}) {{ "within group (order by " ~ order_field ~ " " ~ order ~ ")" if order_field }}
{% endmacro %}
{% macro postgres__array_agg(field, distinct, order_field, order) %}
{# nulls are removed from the array to keep it alligned with the snowflake implementation #}
array_remove(array_agg({{ "distinct" if distinct }} {{ field }} {{ "order by " ~ order_field ~ " " ~ order if order_field }}), null)
{% endmacro %}
{% macro bigquery__array_agg(field, distinct, order_field, order) %}
{# nulls are removed from the array to keep it alligned with the snowflake implementation #}
array_agg({{'distinct' if distinct}} {{field}} ignore nulls {{ "order by " ~ order_field ~ " " ~ order if order_field }})
{% endmacro %}
{% macro duckdb__array_agg(field, distinct, order_field, order) %}
list({{ "distinct" if distinct }} {{ field }} {{ "order by " ~ order_field ~ " " ~ order if order_field }})
{% endmacro %}
{% macro default__array_agg(field, distinct, order_field, order) %}
{{ dbt_graph_theory.adapter_missing_exception() }}
{% endmacro %}