Skip to content

Commit

Permalink
Validating metrics are available for table/column.
Browse files Browse the repository at this point in the history
  • Loading branch information
elongl committed Jul 1, 2024
1 parent cc246b3 commit 8655f51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions macros/edr/data_monitoring/monitors/monitors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,17 @@
'column_boolean': ['count_true', 'count_false']
}) %}
{% endmacro %}

{% macro get_available_table_monitors() %}
{% do return(elementary.get_available_monitors()["table"]) %}
{% endmacro %}

{% macro get_available_column_monitors() %}
{% set available_col_monitors = [] %}
{% for monitor_type, monitors in elementary.get_available_monitors().items() %}
{% if monitor_type.startswith("column") %}
{% do available_col_monitors.extend(monitors) %}
{% endif %}
{% endfor %}
{% do return(available_col_monitors) %}
{% endmacro %}
17 changes: 17 additions & 0 deletions macros/edr/tests/test_collect_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@
{% do exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source')") %}
{% endif %}

{% set available_table_monitors = elementary.get_available_table_monitors() %}
{% set available_col_monitors = elementary.get_available_column_monitors() %}

{% set table_metrics = [] %}
{% set col_to_metrics = {} %}
{% for metric in metrics %}
{% if metric.get("columns") %}
{% if metric.name not in available_col_monitors %}
{% if metric.name in available_table_monitors %}
{% do exceptions.raise_compiler_error("The metric '{}' is a table metric and shouldn't receive 'columns' argument.".format(metric.name)) %}
{% endif %}
{% do exceptions.raise_compiler_error("Unsupported column metric: '{}'.".format(metric.name)) %}
{% endif %}

{% if metric.columns is string %}
{% if metric.columns == "*" %}
{% set columns = adapter.get_columns_in_relation(model_relation) %}
Expand All @@ -50,6 +60,13 @@
{% do exceptions.raise_compiler_error("Unexpected value provided for 'columns' argument.") %}
{% endif %}
{% else %}
{% if metric.name not in available_table_monitors %}
{% if metric.name in available_col_monitors %}
{% do exceptions.raise_compiler_error("The metric '{}' is a column metric and should receive 'columns' argument.".format(metric.name)) %}
{% endif %}
{% do exceptions.raise_compiler_error("Unsupported table metric: '{}'.".format(metric.name)) %}
{% endif %}

{% do table_metrics.append(metric) %}
{% endif %}
{% endfor %}
Expand Down

0 comments on commit 8655f51

Please sign in to comment.