diff --git a/integration_tests/deprecated_tests/macros/e2e_tests/test_config_levels.sql b/integration_tests/deprecated_tests/macros/e2e_tests/test_config_levels.sql index b56798ff8..23781040a 100644 --- a/integration_tests/deprecated_tests/macros/e2e_tests/test_config_levels.sql +++ b/integration_tests/deprecated_tests/macros/e2e_tests/test_config_levels.sql @@ -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) %} diff --git a/macros/edr/system/hooks/on_run_end.sql b/macros/edr/system/hooks/on_run_end.sql index 73b2f1ebd..3d47266ab 100644 --- a/macros/edr/system/hooks/on_run_end.sql +++ b/macros/edr/system/hooks/on_run_end.sql @@ -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 %} @@ -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 %} diff --git a/macros/edr/system/hooks/on_run_start.sql b/macros/edr/system/hooks/on_run_start.sql index 4d86a0ff1..a296e6a28 100644 --- a/macros/edr/system/hooks/on_run_start.sql +++ b/macros/edr/system/hooks/on_run_start.sql @@ -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 %} diff --git a/macros/edr/tests/on_run_start/create_elementary_tests_schema.sql b/macros/edr/tests/on_run_start/create_elementary_tests_schema.sql index ed5d0c9b3..889e97a59 100644 --- a/macros/edr/tests/on_run_start/create_elementary_tests_schema.sql +++ b/macros/edr/tests/on_run_start/create_elementary_tests_schema.sql @@ -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) %} diff --git a/macros/edr/tests/test_all_columns_anomalies.sql b/macros/edr/tests/test_all_columns_anomalies.sql index fb3303a4f..7bc3aab9d 100644 --- a/macros/edr/tests/test_all_columns_anomalies.sql +++ b/macros/edr/tests/test_all_columns_anomalies.sql @@ -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')") }} diff --git a/macros/edr/tests/test_column_anomalies.sql b/macros/edr/tests/test_column_anomalies.sql index d1283b05a..3f815ef61 100644 --- a/macros/edr/tests/test_column_anomalies.sql +++ b/macros/edr/tests/test_column_anomalies.sql @@ -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')") }} diff --git a/macros/edr/tests/test_dimension_anomalies.sql b/macros/edr/tests/test_dimension_anomalies.sql index 69f864c30..56c6cca8c 100644 --- a/macros/edr/tests/test_dimension_anomalies.sql +++ b/macros/edr/tests/test_dimension_anomalies.sql @@ -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')") }} diff --git a/macros/edr/tests/test_event_freshness_anomalies.sql b/macros/edr/tests/test_event_freshness_anomalies.sql index d02222916..59a67b03a 100644 --- a/macros/edr/tests/test_event_freshness_anomalies.sql +++ b/macros/edr/tests/test_event_freshness_anomalies.sql @@ -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')") }} diff --git a/macros/edr/tests/test_exposure_schema_validity.sql b/macros/edr/tests/test_exposure_schema_validity.sql index d4bd21d46..610847d01 100644 --- a/macros/edr/tests/test_exposure_schema_validity.sql +++ b/macros/edr/tests/test_exposure_schema_validity.sql @@ -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 -%} diff --git a/macros/edr/tests/test_json_schema.sql b/macros/edr/tests/test_json_schema.sql index b805ac77d..9abd3baa3 100644 --- a/macros/edr/tests/test_json_schema.sql +++ b/macros/edr/tests/test_json_schema.sql @@ -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 %} diff --git a/macros/edr/tests/test_schema_changes.sql b/macros/edr/tests/test_schema_changes.sql index 9038cc8e1..ec41d6b9f 100644 --- a/macros/edr/tests/test_schema_changes.sql +++ b/macros/edr/tests/test_schema_changes.sql @@ -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')") }} diff --git a/macros/edr/tests/test_schema_changes_from_baseline.sql b/macros/edr/tests/test_schema_changes_from_baseline.sql index 8f006720a..e4bb1680d 100644 --- a/macros/edr/tests/test_schema_changes_from_baseline.sql +++ b/macros/edr/tests/test_schema_changes_from_baseline.sql @@ -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)") }} diff --git a/macros/edr/tests/test_table_anomalies.sql b/macros/edr/tests/test_table_anomalies.sql index d0e059a36..4035b4b57 100644 --- a/macros/edr/tests/test_table_anomalies.sql +++ b/macros/edr/tests/test_table_anomalies.sql @@ -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") }} diff --git a/macros/utils/command_type_utils.sql b/macros/utils/command_type_utils.sql new file mode 100644 index 000000000..1d9c9824e --- /dev/null +++ b/macros/utils/command_type_utils.sql @@ -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 %}