init
This commit is contained in:
16
dbt/macros/common/check_model_exists.sql
Normal file
16
dbt/macros/common/check_model_exists.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
{% macro check_model_exists(model_name) %}
|
||||
{% if execute %}
|
||||
{% if manifest %}
|
||||
{% set model_exists = false %}
|
||||
{% for node in manifest.nodes.values() %}
|
||||
{% if node.resource_type == 'model' and node.name == model_name %}
|
||||
{% set model_exists = true %}
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ return(model_exists) }}
|
||||
{% else %}
|
||||
{{ exceptions.raise_compiler_error("'manifest' object is not available in this context.") }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
15
dbt/macros/common/get_child_models.sql
Normal file
15
dbt/macros/common/get_child_models.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
{% macro get_child_models(model_name) %}
|
||||
{% if execute %}
|
||||
{% set graph = graph.nodes %}
|
||||
{% set children = [] %}
|
||||
{% for node, details in graph.items() %}
|
||||
{% for item in details.depends_on.nodes %}
|
||||
{% if model_name == item.split('.')[2] %}
|
||||
{% do children.append(node.split('.')[2]) %}
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{{ return(children) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
12
dbt/macros/common/get_parent_models.sql
Normal file
12
dbt/macros/common/get_parent_models.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
{% macro get_parent_models(model_name) %}
|
||||
{% if execute %}
|
||||
{% set model = ( graph.nodes.values() | selectattr('name', 'equalto', model_name) | list ).pop() %}
|
||||
{% set depends_on = model.depends_on['nodes'] %}
|
||||
{% set new_depends_on = [] %}
|
||||
{% for item in depends_on %}
|
||||
{% do new_depends_on.append(item.split('.')[2]) %}
|
||||
{% endfor %}
|
||||
{{ return(new_depends_on) }}
|
||||
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
12
dbt/macros/common/get_table_qualified_name.sql
Normal file
12
dbt/macros/common/get_table_qualified_name.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
{% macro get_table_qualified_name(model_name) %}
|
||||
{% if execute %}
|
||||
{% set models = graph.nodes.values() %}
|
||||
{% set model = (models | selectattr('name', 'equalto', model_name) | list).pop() %}
|
||||
{% if model is not none %}
|
||||
{% set table_qualified_name = model.schema ~ '.' ~ model.alias if model.alias is not none and model.alias != '' else model.schema ~ '.' ~ model.name %}
|
||||
{{ return(table_qualified_name) }}
|
||||
{% else %}
|
||||
{{ exceptions.raise("Model not found: " ~ model_name) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
Reference in New Issue
Block a user