Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Dynamically switch references for model_run_results_v4 (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Yu ISHIKAWA <yuu.ishikawa@gmail.com>

Signed-off-by: Yu ISHIKAWA <yuu.ishikawa@gmail.com>
  • Loading branch information
yu-iskw authored Aug 22, 2022
1 parent 94fe596 commit db6b0f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dbt_artifacts_models/macros/get_dbt_minor_version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% macro get_dbt_minor_version(version) %}
{% set re = modules.re %}
{% set pattern = '[\.][^\.]+$' %}
{% set dbt_minor_version = re.sub(pattern, '', version) %}
{{ return(dbt_minor_version) }}
{% endmacro %}

{% macro test_get_dbt_minor_version() %}
{% set result = get_dbt_minor_version("1.0.3") %}
{% if result != "1.0" %}
{{ exceptions.raise_compiler_error("Expected 1.0, but " ~ result) }}
{% endif %}

{% set result = get_dbt_minor_version("1.1.0") %}
{% if result != "1.1" %}
{{ exceptions.raise_compiler_error("Expected 1.1, but " ~ result) }}
{% endif %}

{% set result = get_dbt_minor_version("1.1.1") %}
{% if result != "1.1" %}
{{ exceptions.raise_compiler_error("Expected 1.1, but " ~ result) }}
{% endif %}

{% set result = get_dbt_minor_version("1.2.0-rc1") %}
{% if result != "1.2" %}
{{ exceptions.raise_compiler_error("Expected 1.2, but " ~ result) }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% set re = modules.re %}
{% set dbt_minor_version = get_dbt_minor_version(version=dbt_version) %}

{% set project = var('dbt_artifacts_loader')['project'] %}
{% set dataset = var('dbt_artifacts_loader')['dataset'] %}

Expand All @@ -22,9 +25,17 @@ WITH run_results AS (
run_results.*,
(SELECT AS STRUCT models.*) AS model,
FROM {{ ref("expanded_run_results_v4") }} AS run_results
{% if dbt_minor_version == "1.0" %}
LEFT OUTER JOIN {{ ref("parsed_model_node_v4") }} AS models
ON run_results.unique_id = models.unique_id
AND ABS(DATETIME_DIFF(run_results.metadata.generated_at, models.metadata.generated_at, DAY)) <= 2
{% elif dbt_minor_version == "1.1" %}
LEFT OUTER JOIN {{ ref("parsed_model_node_v5") }} AS models
ON run_results.unique_id = models.unique_id
AND ABS(DATETIME_DIFF(run_results.metadata.generated_at, models.metadata.generated_at, DAY)) <= 2
{% else %}
{{ exceptions.raise_compiler_error("Unexpected dbt version: " ~ dbt_minor_version) }}
{% endif %}
WHERE models.unique_id IS NOT NULL
AND timing_name IN ("execute")
)
Expand Down

0 comments on commit db6b0f6

Please sign in to comment.