Skip to content

Commit

Permalink
bugfix - support dbt's retry command (and refactor a bit usage of fla…
Browse files Browse the repository at this point in the history
…gs.WHICH)
  • Loading branch information
haritamar committed Dec 14, 2023
1 parent ec6b540 commit 96f0990
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% test config_levels(model, expected_config, timestamp_column, time_bucket, where_expression, anomaly_sensitivity, anomaly_direction, days_back, backfill_days, seasonality, min_training_set_size) %}
{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{%- set unexpected_config = [] %}
{%- set model_relation = dbt.load_relation(model) %}

Expand Down
6 changes: 3 additions & 3 deletions macros/edr/system/hooks/on_run_end.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% macro on_run_end() %}
{%- if execute and flags.WHICH not in ['generate', 'serve'] %}
{%- if execute and not elementary.is_docs_command(flags.WHICH) %}
{% set edr_cli_run = elementary.get_config_var('edr_cli_run') %}
{% if not execute or edr_cli_run %}
{% do return("") %}
{% endif %}

{% if flags.WHICH in ['run', 'build'] %}
{% if elementary.is_run_command(flags.WHICH) %}
{% do elementary.insert_metrics() %}
{% endif %}

Expand All @@ -17,7 +17,7 @@
{% do elementary.upload_run_results() %}
{% endif %}

{% if flags.WHICH in ['test', 'build'] and not elementary.get_config_var('disable_tests_results') %}
{% if elementary.is_test_command(flags.WHICH) and not elementary.get_config_var('disable_tests_results') %}
{% do elementary.handle_tests_results() %}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion macros/edr/system/hooks/on_run_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% do recommend_dbt_core_artifacts_upgrade() %}
{% do elementary.init_elementary_graph() %}

{% if flags.WHICH in ['test', 'build'] %}
{% if elementary.is_test_command(flags.WHICH) %}
{{ elementary.create_elementary_tests_schema() }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro create_elementary_tests_schema() %}
{% if execute and flags.WHICH in ['test', 'build'] %}
{% if execute and elementary.is_test_command(flags.WHICH) %}
{% set database_name, schema_name = elementary.get_package_database_and_schema('elementary') %}
{% set tests_schema_name = elementary.get_elementary_tests_schema(database_name, schema_name) %}
{%- if tests_schema_name != schema_name and not adapter.check_schema_exists(database_name, tests_schema_name) %}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_all_columns_anomalies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- depends_on: {{ ref('data_monitoring_metrics') }}
-- depends_on: {{ ref('dbt_run_results') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_column_anomalies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- depends_on: {{ ref('data_monitoring_metrics') }}
-- depends_on: {{ ref('dbt_run_results') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_dimension_anomalies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- depends_on: {{ ref('data_monitoring_metrics') }}
-- depends_on: {{ ref('dbt_run_results') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_event_freshness_anomalies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- depends_on: {{ ref('data_monitoring_metrics') }}
-- depends_on: {{ ref('dbt_run_results') }}

{% if execute and flags.WHICH in ['test', 'build'] %}
{% if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_exposure_schema_validity.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% test exposure_schema_validity(model, exposures, node, columns) %}
{%- if not execute or flags.WHICH not in ['test', 'build'] -%}
{%- if not execute or not elementary.is_test_command(flags.WHICH) -%}
{%- do return(none) -%}
{%- endif -%}

Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_json_schema.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% test json_schema(model, column_name, where_expression) %}
{{ config(fail_calc = 'fail_count') }}

{% if not execute or flags.WHICH not in ['test', 'build'] %}
{% if not execute or not elementary.is_test_command(flags.WHICH) %}
{% do return(none) %}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_schema_changes.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% test schema_changes(model) %}
-- depends_on: {{ ref('schema_columns_snapshot') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_schema_changes_from_baseline.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% test schema_changes_from_baseline(model, fail_on_added=False, enforce_types=False) %}
-- depends_on: {{ ref('schema_columns_snapshot') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source)") }}
Expand Down
2 changes: 1 addition & 1 deletion macros/edr/tests/test_table_anomalies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- depends_on: {{ ref('data_monitoring_metrics') }}
-- depends_on: {{ ref('dbt_run_results') }}

{%- if execute and flags.WHICH in ['test', 'build'] %}
{%- if execute and elementary.is_test_command(flags.WHICH) %}
{% set model_relation = elementary.get_model_relation_for_test(model, context["model"]) %}
{% if not model_relation %}
{{ exceptions.raise_compiler_error("The test has unsupported configuration, please contact Elementary support") }}
Expand Down
11 changes: 11 additions & 0 deletions macros/utils/command_type_utils.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% macro is_test_command(command) %}
{% do return(command in ['test', 'build']) %}
{% endmacro %}

{% macro is_run_command(command) %}
{% do return(command in ['run', 'build']) %}
{% endmacro %}

{% macro is_docs_command(command) %}
{% do return(command in ['generate', 'serve']) %}
{% endmacro %}

0 comments on commit 96f0990

Please sign in to comment.