Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions macros/utils/graph/get_elementary_relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@
{% if this and this.database == elementary_database and this.schema == elementary_schema and this.identifier == identifier_alias %}
{% do return(this) %}
{% endif %}
{% do return(
adapter.get_relation(
elementary_database, elementary_schema, identifier_alias
{% set relation = adapter.get_relation(
elementary_database, elementary_schema, identifier_alias
) %}
{% if relation is not none %} {% do return(relation) %} {% endif %}
{# Relation not found in the target schema. Under dbt deferral
(--favor-state / --defer) the Elementary models may exist only
in the deferred (e.g. prod) schema and not in the current
target. Construct a relation from the graph node coordinates
so the generated SQL references the correct schema instead of
rendering "from None". #}
{% set is_defer = (
(
invocation_args_dict.get("defer", false)
or invocation_args_dict.get("favor_state", false)
)
if invocation_args_dict
else false
) %}
{% if identifier_node and is_defer %}
{% do return(
api.Relation.create(
database=elementary_database,
schema=elementary_schema,
identifier=identifier_alias,
)
) %}
{% endif %}
{%- endif %}
{% endmacro %}
Loading