-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from dbt-labs/fix/update-grain-of-multiple_sou…
…rces_joined Fix/update grain of multiple sources joined
- Loading branch information
Showing
10 changed files
with
120 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
parent,num_of_leaf_children | ||
fct_model_6,3 | ||
parent,leaf_children | ||
fct_model_6,"report_1, report_2, report_3" |
5 changes: 2 additions & 3 deletions
5
integration_tests/seeds/dag/test_fct_multiple_sources_joined.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
parent,parent_resource_type,child,child_resource_type,distance | ||
source_1.table_1,source,stg_model_2,model,1 | ||
source_1.table_2,source,stg_model_2,model,1 | ||
child,source_parents | ||
stg_model_2,"source_1.table_1, source_1.table_2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
parent,parent_resource_type,child,child_resource_type,distance | ||
source_1.table_1,source,stg_model_2,model,1 | ||
source_1.table_1,source,stg_model_1,model,1 | ||
source_1.table_2,source,stg_model_2,model,1 | ||
source_1.table_2,source,int_model_4,model,1 | ||
parent,model_children | ||
source_1.table_2,"int_model_4, stg_model_2" | ||
source_1.table_1,"stg_model_1, stg_model_2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{% macro listagg(measure, delimiter_text="','", order_by_clause=none, limit_num=none) -%} | ||
{{ return(adapter.dispatch('listagg') (measure, delimiter_text, order_by_clause, limit_num)) }} | ||
{%- endmacro %} | ||
|
||
{% macro default__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} | ||
|
||
{% if limit_num -%} | ||
array_to_string( | ||
array_slice( | ||
array_agg( | ||
{{ measure }} | ||
){% if order_by_clause -%} | ||
within group ({{ order_by_clause }}) | ||
{%- endif %} | ||
,0 | ||
,{{ limit_num }} | ||
), | ||
{{ delimiter_text }} | ||
) | ||
{%- else %} | ||
listagg( | ||
{{ measure }}, | ||
{{ delimiter_text }} | ||
) | ||
{% if order_by_clause -%} | ||
within group ({{ order_by_clause }}) | ||
{%- endif %} | ||
{%- endif %} | ||
|
||
{%- endmacro %} | ||
|
||
{% macro bigquery__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} | ||
|
||
string_agg( | ||
{{ measure }}, | ||
{{ delimiter_text }} | ||
{% if order_by_clause -%} | ||
{{ order_by_clause }} | ||
{%- endif %} | ||
{% if limit_num -%} | ||
limit {{ limit_num }} | ||
{%- endif %} | ||
) | ||
|
||
{%- endmacro %} | ||
|
||
{% macro postgres__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} | ||
|
||
{% if limit_num -%} | ||
array_to_string( | ||
(array_agg( | ||
{{ measure }} | ||
{% if order_by_clause -%} | ||
{{ order_by_clause }} | ||
{%- endif %} | ||
))[1:{{ limit_num }}], | ||
{{ delimiter_text }} | ||
) | ||
{%- else %} | ||
string_agg( | ||
{{ measure }}, | ||
{{ delimiter_text }} | ||
{% if order_by_clause -%} | ||
{{ order_by_clause }} | ||
{%- endif %} | ||
) | ||
{%- endif %} | ||
|
||
{%- endmacro %} | ||
|
||
{# if there are instances of delimiter_text within your measure, you cannot include a limit_num #} | ||
{% macro redshift__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} | ||
|
||
{% if limit_num -%} | ||
{% set delimiter_text_strip = delimiter_text|replace("'","") %} | ||
{% set regex %}'([^{{ delimiter_text_strip }}]+{{ delimiter_text_strip }}){1,{{ limit_num - 1}}}[^{{ delimiter_text_strip }}]+'{% endset %} | ||
regexp_substr( | ||
listagg( | ||
{{ measure }}, | ||
{{ delimiter_text }} | ||
) | ||
{% if order_by_clause -%} | ||
within group ({{ order_by_clause }}) | ||
{%- endif %} | ||
,{{ regex }} | ||
) | ||
{%- else %} | ||
listagg( | ||
{{ measure }}, | ||
{{ delimiter_text }} | ||
) | ||
{% if order_by_clause -%} | ||
within group ({{ order_by_clause }}) | ||
{%- endif %} | ||
{%- endif %} | ||
|
||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters