Skip to content

Commit

Permalink
Fix ref_cte_name
Browse files Browse the repository at this point in the history
  • Loading branch information
psousa50 committed Sep 19, 2023
1 parent a22471e commit 1d2bf57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
12 changes: 0 additions & 12 deletions integration-tests/tests/unit/model_b_references_a.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,3 @@
select 1 as a, 'b' as b
{% endcall %}
{% endcall %}

UNION ALL

{% call test_condition_on_model_query('model_b_references_a', "should ", {},
assert_should_contain, dbt_unit_testing.quote_identifier("model_a")) %}
{% call dbt_unit_testing.mock_ref ('model_a') %}
select 1 as id
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 1 as id
{% endcall %}
{% endcall %}
4 changes: 2 additions & 2 deletions macros/sql_builders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{% if node.package_name != model.package_name %}
{% set parts = [node.package_name] + parts %}
{% endif %}
{% if node.version is not none %}
{% if dbt_unit_testing.has_value(node.version)%}
{% set parts = parts + [node.version] %}
{% endif %}
{{ return (dbt_unit_testing.quote_identifier(parts | join("__"))) }}
Expand Down Expand Up @@ -81,7 +81,7 @@
{%- if node.resource_type == "source" %}
{% set name = node.identifier %}
{%- elif node.resource_type == "snapshot" %}
{%- if node.config.alias is not none %}
{%- if dbt_unit_testing.has_value(node.config.alias) %}
{% set name = node.config.alias %}
{%- else %}
{% set name = node.name %}
Expand Down
10 changes: 7 additions & 3 deletions macros/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,28 @@
{{ return (graph.nodes[node_id] if node_id in graph.nodes else graph.sources[node_id]) }}
{% endmacro %}

{% macro has_value(v) %}
{{ return (v is defined and v is not none) }}
{% endmacro %}

{% macro model_node (node) %}
{% set graph_nodes = graph.nodes.values() |
selectattr('resource_type', 'in', ['model', 'snapshot', 'seed']) |
selectattr('package_name', 'equalto', node.package_name) |
selectattr('name', 'equalto', node.name) |
list %}
{% if graph_nodes | length > 0 %}
{% if node.version is defined and node.version is not none %}
{% if dbt_unit_testing.has_value(node.version) %}
{% set graph_nodes = graph_nodes | selectattr('version', 'equalto', node.version) | list %}
{% else %}
{% set latest_version = graph_nodes[0].latest_version %}
{% if latest_version is defined and latest_version is not none %}
{% if dbt_unit_testing.has_value(latest_version) %}
{% set graph_nodes = graph_nodes | selectattr('version', 'equalto', latest_version) | list %}
{% endif %}
{% endif %}
{% endif %}
{% if graph_nodes | length == 0 %}
{% set node_version = '_v' ~ node.version if node.version is defined and node.version is not none else '' %}
{% set node_version = '_v' ~ node.version if dbt_unit_testing.has_value(node.version) else '' %}
{{ dbt_unit_testing.raise_error("Node " ~ node.package_name ~ "." ~ node.name ~ node_version ~ " not found.") }}
{% endif %}
{% set graph_node = graph_nodes[0] %}
Expand Down

0 comments on commit 1d2bf57

Please sign in to comment.