-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
override model yaml macro in "samples" folder
- Loading branch information
Faith Lierheimer
committed
Jun 10, 2024
1 parent
d71e235
commit 00a1488
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{% macro generate_column_yaml(column, model_yaml, column_desc_dict, parent_column_name="") %} | ||
{% if parent_column_name %} | ||
{% set column_name = parent_column_name ~ "." ~ column.name %} | ||
{% else %} | ||
{% set column_name = column.name %} | ||
{% endif %} | ||
-- removing "lower" from whole macro | ||
{% do model_yaml.append(' - name: ' ~ column.name) %} | ||
{% do model_yaml.append(' description: "' ~ column_desc_dict.get(column.name) ~ '"') %} | ||
{% do model_yaml.append('') %} | ||
|
||
{% if column.fields|length > 0 %} | ||
{% for child_column in column.fields %} | ||
{% set model_yaml = codegen.generate_column_yaml(child_column, model_yaml, column_desc_dict, parent_column_name=column_name) %} | ||
{% endfor %} | ||
{% endif %} | ||
{% do return(model_yaml) %} | ||
{% endmacro %} | ||
|
||
{% macro generate_model_yaml(model_names=[], upstream_descriptions=False) %} | ||
|
||
{% set model_yaml=[] %} | ||
|
||
{% do model_yaml.append('version: 2') %} | ||
{% do model_yaml.append('') %} | ||
{% do model_yaml.append('models:') %} | ||
|
||
{% if model_names is string %} | ||
{{ exceptions.raise_compiler_error("The `model_names` argument must always be a list, even if there is only one model.") }} | ||
{% else %} | ||
{% for model in model_names %} | ||
{% do model_yaml.append(' - name: ' ~ model ) %} | ||
{% do model_yaml.append(' description: ""') %} | ||
{% do model_yaml.append(' columns:') %} | ||
|
||
{% set relation=ref(model) %} | ||
{%- set columns = adapter.get_columns_in_relation(relation) -%} | ||
{% set column_desc_dict = codegen.build_dict_column_descriptions(model) if upstream_descriptions else {} %} | ||
|
||
{% for column in columns %} | ||
{% set model_yaml = codegen.generate_column_yaml(column, model_yaml, column_desc_dict) %} | ||
{% endfor %} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if execute %} | ||
|
||
{% set joined = model_yaml | join ('\n') %} | ||
{{ log(joined, info=True) }} | ||
{% do return(joined) %} | ||
|
||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
packages: | ||
- package: dbt-labs/codegen | ||
version: 0.9.0 | ||
- package: dbt-labs/dbt_utils | ||
version: 1.1.0 | ||
- package: dbt-labs/audit_helper | ||
version: 0.9.0 | ||
- package: brooklyn-data/dbt_artifacts | ||
version: 2.6.2 | ||
- package: dbt-labs/dbt_project_evaluator | ||
version: 0.6.0 | ||
- package: calogica/dbt_expectations | ||
version: 0.8.5 | ||
- package: calogica/dbt_date | ||
version: 0.7.2 | ||
sha1_hash: a17b7bdcdb4efda257369bdfd548f5104eb383a3 |