-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New functionality - Retrieve the description for identical column nam…
…es from upstream models (#61) * Update gitignore for latest version of dbt * Add macros to retrieve info from graph * Update README with new parameter for generate_model_yaml * Add integration test for the new feature * Update CHANGELOG with upstream_descriptions flag * Fix typos * Update CI steps to run the models before testing
- Loading branch information
Showing
10 changed files
with
77 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
target/ | ||
dbt_modules/ | ||
dbt_packages/ | ||
logs/ |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select | ||
* | ||
from {{ ref('model_data_a') }} |
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,3 @@ | ||
select | ||
* | ||
from {{ ref('data__a_relation') }} |
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,7 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: model_data_a | ||
columns: | ||
- name: col_a | ||
description: description column a |
22 changes: 22 additions & 0 deletions
22
integration_tests/tests/test_generate_model_yaml_upstream_descriptions.sql
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,22 @@ | ||
{% set actual_model_yaml = codegen.generate_model_yaml( | ||
model_name='child_model', | ||
upstream_descriptions=True | ||
) | ||
%} | ||
|
||
{% set expected_model_yaml %} | ||
version: 2 | ||
|
||
models: | ||
- name: child_model | ||
description: "" | ||
columns: | ||
- name: col_a | ||
description: "description column a" | ||
|
||
- name: col_b | ||
description: "" | ||
|
||
{% endset %} | ||
|
||
{{ assert_equal (actual_model_yaml | trim, expected_model_yaml | trim) }} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{# retrieve models directly upstream from a given model #} | ||
{% macro get_model_dependencies(model_name) %} | ||
{% for node in graph.nodes.values() | selectattr('name', "equalto", model_name) %} | ||
{{ return(node.depends_on.nodes) }} | ||
{% endfor %} | ||
{% endmacro %} | ||
|
||
|
||
{# add to an input dictionary entries containing all the column descriptions of a given model #} | ||
{% macro add_model_column_descriptions_to_dict(model_name,dict_with_descriptions={}) %} | ||
{% for node in graph.nodes.values() | selectattr('name', "equalto", model_name) %} | ||
{% for col_name, col_values in node.columns.items() %} | ||
{% do dict_with_descriptions.update( {col_name: col_values.description} ) %} | ||
{% endfor %} | ||
{% endfor %} | ||
{{ return(dict_with_descriptions) }} | ||
{% endmacro %} | ||
|
||
{# build a global dictionary looping through all the direct parents models #} | ||
{# if the same column name exists with different descriptions it is overwritten at each loop #} | ||
{% macro build_dict_column_descriptions(model_name) %} | ||
{% if execute %} | ||
{% set glob_dict = {} %} | ||
{% for full_model in codegen.get_model_dependencies(model_name) %} | ||
{% do codegen.add_model_column_descriptions_to_dict(full_model.split('.')[-1],glob_dict) %} | ||
{% endfor %} | ||
{{ return(glob_dict) }} | ||
{% endif %} | ||
{% endmacro %} |