Add order_by to string_agg for DuckDB

This commit is contained in:
Benoit Perigaud
2023-03-13 09:43:27 +01:00
parent e26dbb44ba
commit 57ff0cdcd1
5 changed files with 5 additions and 8 deletions

View File

@@ -14,14 +14,11 @@
{% if limit_num -%}
{%- do exceptions.raise_compiler_error("listagg on DuckDB doesn't support limit_num") -%}
{%- endif %}
{% if order_by_clause -%}
{%- do exceptions.warn("listagg on DuckDB doesn't support order_by_clause, you should order your data beforehand") -%}
{%- endif %}
string_agg(
{{ measure }}
, {{ delimiter_text }}
{{ order_by_clause }}
)
{%- endmacro %}

View File

@@ -37,7 +37,7 @@ model_fanout_agg as (
{{ dbt.listagg(
measure = 'child',
delimiter_text = "', '",
order_by_clause = 'order by child' if target.type in ['snowflake','redshift'])
order_by_clause = 'order by child' if target.type in ['snowflake','redshift','duckdb'])
}} as leaf_children
from model_fanout
group by 1, 2

View File

@@ -16,7 +16,7 @@ multiple_sources_joined as (
{{ dbt.listagg(
measure='parent',
delimiter_text="', '",
order_by_clause='order by parent' if target.type in ['snowflake','redshift'])
order_by_clause='order by parent' if target.type in ['snowflake','redshift','duckdb'])
}} as source_parents
from direct_source_relationships
group by 1

View File

@@ -16,7 +16,7 @@ source_fanout as (
{{ dbt.listagg(
measure='child',
delimiter_text="', '",
order_by_clause='order by child' if target.type in ['snowflake','redshift'])
order_by_clause='order by child' if target.type in ['snowflake','redshift','duckdb'])
}} as model_children
from direct_source_relationships
group by 1

View File

@@ -17,7 +17,7 @@ appropriate_prefixes as (
{{ dbt.listagg(
measure='prefix_value',
delimiter_text="', '",
order_by_clause='order by prefix_value' if target.type in ['snowflake','redshift'])
order_by_clause='order by prefix_value' if target.type in ['snowflake','redshift','duckdb'])
}} as appropriate_prefixes
from naming_convention_prefixes
group by model_type