-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
110 additions
and
51 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,56 @@ | ||
--this model override allows users to avoid dbt's "auto lowercasing" behavior when using codegen to generate model yaml. | ||
--To actually use this macro, put it in the macros folder and name it generate_model_yaml.sql. | ||
{% 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
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 |
---|---|---|
|
@@ -46,4 +46,4 @@ final as ( | |
from joined | ||
) | ||
|
||
select * from final | ||
select * from final |
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
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
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
Oops, something went wrong.